COBOL COMP-1

COBOL COMPUTATION COBOL COMP-2

Advertisements


COMP-1 usage clause will be called as Floating point.

COMP-1 usage clause is applicable to single floating point data type.

COMP-1 is specified for internal floating point items which is single precision.

COMP-1 items are 4 bytes long.

PICTURE clause should not be specified.

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

In the 4 bytes, leftmost 8 bits to store exponent and remaining 24 bits stores mantissa.

The COMP-1 memory calculations like below.


PictureNumber of Bytes
9(16)- 1 word4

COMP-1 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-1. 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 8 bits) and 9999 is mantissa (stored in remaining 24 bits).

Let’s discuss how the data stored in memory.


Example:

01 WS-COMP-1	COMP-1.

MOVE 255	TO WS-COMP-1.
DISPLAY ‘COMPUTATION-1 DISPLAY :’ WS-COMP-1.

Output:

COMPUTATION-1 DISPLAY : 	..

Hex-on Output:

0F
0F

The four bytes Hex-on display will be like below.


Diagram:



Practicle Example:


Code:


 IDENTIFICATION DIVISION.                                         
 PROGRAM-ID. COMP1.                                               
 ENVIRONMENT DIVISION.                                            
 DATA DIVISION.                                                   
 WORKING-STORAGE SECTION.                                         
 01 COMP1-NM              PIC 9(03) USAGE COMP-1 VALUE '256'.     
 PROCEDURE DIVISION.                                              
     DISPLAY 'COMPUTATION-1..'.                                   
     DISPLAY 'COMPUTATION1 - NUMERIC [9(01) - 9(16)]-> 4 BYTES '. 
     DISPLAY COMP1-NM.                                            
     STOP RUN.                                                    


COBOL COMPUTATION COBOL COMP-2

Advertisements