Professional Documents
Culture Documents
Comp, Comp1, Comp2 and Comp3 in Cobol
Comp, Comp1, Comp2 and Comp3 in Cobol
Comp, Comp1, Comp2 and Comp3 in Cobol
COBOL
COMP:
Let’s take an example for displaying all data types which are passing through
program and see how it is after writing to the program.
IDENTIFICATION DIVISION.
PROGRAM-ID. COM1.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC S9(8) USAGE COMP.
PROCEDURE DIVISION.
INITIALIZE A
MOVE '1234567' TO A.
DISPLAY A.
DISPLAY 'LENGTH ' LENGTH OF A.
STOP RUN.
COMP-1:
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.
Picture Number of Bytes
9(16)- 1 word 4
COMP-1 will store the data in the format of mantissa and exponent. Here
Mantissa is numeric value and exponent is the precision number.
IDENTIFICATION DIVISION.
PROGRAM-ID. COM1.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A USAGE COMP-1.
PROCEDURE DIVISION.
INITIALIZE A
MOVE '1234567' TO A.
DISPLAY A.
DISPLAY 'LENGTH ' LENGTH OF A.
STOP RUN.
COMP-2:
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.