Open In App

COMP-2 in COBOL

In COMP Usage data will get stored in the complete binary form. Based on the usage the data will get stored either in HALF-WORD or FULL-WORD. HALF-WORD which is nothing but 2-bytes data and FULL-WORD is nothing but 4 bytes of data.

When comes COMP-2, is similar to COMP-1. In COMP-1 data will get stored in one word in the floating point form whereas in COMP-2 data will get stored or represented in two words of storage.



Features:

Example:




Program for COMP-2 in COBOL
IDENTIFICATION DIVISION.
PROGRAM-ID. Comp2-Code.
ENVIRONMENT DIVISION.
DATA DIVISION.
    WORKING-STORAGE SECTION.
        77 WS-VAL1  PIC 9(2USAGE IS COMP.
        77 WS-VAL2  PIC 9(3USAGE IS COMP.
        77 WS-VAL3  PIC 9(6USAGE IS COMP.
        77 WS-VAL5  USAGE IS COMP-2.
PROCEDURE DIVISION.
    DISPLAY 'COMP USAGE DISPLAY'.
        MOVE 99 TO WS-VAL1.
    DISPLAY 'VALUE OF WS-VAL1 IS: ' WS-VAL1.
    DISPLAY 'LENGTH OF WS-VAL1: ' LENGTH OF WS-VAL1.
        MOVE 99 TO WS-VAL2.
    DISPLAY 'VALUE OF WS-VAL2 IS: ' WS-VAL2.
    DISPLAY 'LENGTH OF WS-VAL2: ' LENGTH OF WS-VAL2.
        MOVE 99 TO WS-VAL3.
    DISPLAY 'VALUE OF WS-VAL3 IS: ' WS-VAL3.
    DISPLAY 'LENGTH OF WS-VAL3: ' LENGTH OF WS-VAL3.
    DISPLAY '                                       '
    DISPLAY 'COMP-2 USAGE DISPLAY'.
        MOVE 999 TO WS-VAL5.
    DISPLAY 'VALUE OF WS-VAL5 IS: ' WS-VAL5.
    DISPLAY 'LENGTH OF WS-VAL5: ' LENGTH OF WS-VAL5.
STOP RUN.

Output:



 

Explanation:

In this example, we are displaying the comparison example for COMP and COMP-2. So we can see that the length of the COMP variables are varying based on the input data but for the COMP-2 variable length is 8 bytes and also we are not specifying the PICTURE Clause.


Article Tags :