Assumed Decimal Point-Data Type Example


Scenario - Below example describes about the assumed decimal point data type declaration and usage in COBOL programming.

Code -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. ADECPDT.
       AUTHOR. MTH.

       DATA DIVISION. 
       WORKING-STORAGE SECTION.
       01 WS-VARS.
          05 WS-ASSUM-DP            PIC 9(03)V9(2).  
          05 WS-ASSUM-DSPL          PIC 9(03)P. 
          05 WS-ASSUM-DSPR          PIC P9(02). 

       PROCEDURE DIVISION.

           MOVE 123.45              TO  WS-ASSUM-DP
                                        WS-ASSUM-DSPL
                                        WS-ASSUM-DSPR.

           DISPLAY "DISLAY FOR 9(03)V9(2):  " WS-ASSUM-DP.
           DISPLAY "DISLAY FOR 9(03)P    :  " WS-ASSUM-DSPL.
           DISPLAY "DISLAY FOR P9(02)    :  " WS-ASSUM-DSPR.

           STOP RUN. 

Output -

DISLAY FOR 9(03)V9(2):  12345
DISLAY FOR 9(03)P    :  012
DISLAY FOR P9(02)    :  50

Explaining example -

In the above example:

  • The assumed decimal variable WS-ASSUM-DP displays value without decimal; however, it uses the decimal value in all calculations.
  • Assumed decimal scaling variable WS-ASSUM-DSPL displays value 12 and ignores the rightmost digit before the decimal because of the right justification.
  • Assumed decimal scaling variable WS-ASSUM-DSPR displays value 5 and ignores the leftmost digit before the decimal because of the left justification after the decimal.