Summary -

In this topic, we described about the below sections -

In some calculations, the decimal values are required to be handled like numbers. When a data comes as a decimal to the program, a data item should declare with decimal point to handle the decimal value.

Decimal point declares only with a combination of numeric data type that is used to handle the numeric values.

In COBOL, the decimal point declaration is two types -

  • Real Decimal Point
  • Implied Decimal Point/Assumed Decimal Point

Real Decimal Point -

Declaring a data item with a period(.) for a decimal value. The decimal point known as a real decimal point. The real decimal point counted in the size of the data item.

The presence of the "." in the PIC causes a real decimal in the memory. For example, the real decimal declaration to store the decimal value 1234.55.

01 DECIMAL-VAL    PIC 9(4).9(2).

In the above example, the DECIMAL-VALUE contains 1234.55 and no change in the display.

Implied Decimal Point/Assumed Decimal Point -

Implies a decimal point at a specified location in a field, but not actually stored. The implied decimal is indicated by a "V" in the PICTURE clause.

Implied decimal point also known as Assumed decimal point. Not counted in the size of the data item. Assumed decimal can apply to any kind of numeric field including a packed or comp-3 field.

The assumed decimal point symbol V is redundant as either the leftmost or rightmost character within such a PICTURE description.For example, the assumed decimal declaration to store the decimal value 1234.55.

01 DECIMAL-VAL      PIC 9(4)V9(2).

In the above example, the DECIMAL-VALUE contains 123455 and removes the decimal point in display. However, the value in the assumption is 1234.55.

Note! The dot or period is declared only for display or reporting purpose.

Assumed decimal scaling position -

Used to specify the location of an assumed decimal point when the decimal point is not within the number. Assumed decimal scaling position is represented by the 'P'.

Not counted in the size of the data item. Scaling position characters are counted to determine the maximum number of digit positions in numeric-edited items or in arithmetic operands.

The size of the value is the number of digit positions represented by the PICTURE character-string. The symbol P specified a scaling position and implies an assumed decimal point to the left of the Ps if the Ps are leftmost PICTURE characters or to the right of the Ps if the Ps are rightmost PICTURE characters.


Practical Example -

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

Code -

Decimal Point Data Type Program Code
=COLS> ----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
****** ***************************** Top of Data ******************************
000001        IDENTIFICATION DIVISION.                                         
000002        PROGRAM-ID. ADECPDT.                                             
000003        AUTHOR. MTH.                                                     
000004                                                                         
000005        DATA DIVISION.                                                   
000006        WORKING-STORAGE SECTION.                                         
000007        01 WS-VARS.                                                      
000008           05 WS-REAL-DP             PIC 9(03)V9(2).                     
000009           05 WS-ASSUM-DP            PIC 9(03).9(2).                     
000010           05 WS-ASSUM-DSPL          PIC 9(03)P.                         
000011           05 WS-ASSUM-DECR          PIC P9(03).                         
000012                                                                         
000013        PROCEDURE DIVISION.                                              
000014                                                                         
000015            MOVE 123.45              TO  WS-REAL-DP                      
000016                                         WS-ASSUM-DP                     
000017                                         WS-ASSUM-DSPL                   
000018                                         WS-ASSUM-DECR.                  
000019                                                                         
000020            DISPLAY "DISLAY FOR 9(03)V9(2):  " WS-REAL-DP.               
000021            DISPLAY "DISLAY FOR 9(03).9(2):  " WS-ASSUM-DP.              
000022            DISPLAY "DISLAY FOR 9(03)P    :  " WS-ASSUM-DSPL.            
000023            DISPLAY "DISLAY FOR P9(03)    :  " WS-ASSUM-DECR.            
000024                                                                         
000025            STOP RUN.                                                    
****** **************************** Bottom of Data ****************************

Output -

Decimal Point Data Type Program Output