COBOL Comp-1 COBOL Comp-3

COMP-2 usage clause will be called as Hexadecimal form.

COMP-2 usage clause applicable to double floating point data type.

COMP-2 is specified for internal floating point items which is double precision.

COMP-2 items are 8 bytes long.

PICTURE clause should not be specified.

COMP-2 allows Signed floating point item where the sign will store on leftmost byte first bit which is allocated to exponent.

In the 8 bytes, leftmost 12 bits to store exponent and remaining 52 bits stores mantissa.

The COMP-2 memory calculations like below.

PictureNumber of Bytes
9(32)- 2 word8

COMP-2 will store the data in the format of mantissa and exponent.

Here Mantissa is numeric value and exponent is the precision number.

For example, 9.999 value needs to be stored in COMP-2. The data can be stored in the memory like 9999 * 10-3.

9.999 equal to 9999 * 10-3.

In the above, 10-3 is exponent value (stored in left most 12 bits) and 9999 is mantissa (stored in remaining 52 bits).

Practicle Example:


 IDENTIFICATION DIVISION.                                         
 PROGRAM-ID. COMP2.                                               
 ENVIRONMENT DIVISION.                                            
 DATA DIVISION.                                                   
 WORKING-STORAGE SECTION.                                        
 01 COMP2-NM              PIC 9(03) USAGE COMP-2 VALUE '256'.     
 PROCEDURE DIVISION.                                              
     DISPLAY 'COMPUTATION-2..'.                                   
     DISPLAY 'COMPUTATION2 - NUMERIC [9(01) - 9(32)]-> 8 BYTES '. 
     DISPLAY COMP2-NM.                                            
     STOP RUN.                                                    

COBOL Comp-1 COBOL Comp-3