Open In App

COMP-1 in COBOL

Improve
Improve
Like Article
Like
Save
Share
Report

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 having the range of -32,768 to +32,767 and FULL-WORD is nothing but 4-bytes of data with-in the range of -2,147,483,648 to +2,147,483,648.

When it comes to COMP-1 , so in COMP-1 data will get stored in one-word in the floating point form. Actually it will represent in the hexadecimal form, which is suitable for all types of arithmetic operation.

We need not specifically use the PICTURE Clause for COMP-1 variables, Because PIC will helps to create relation between data name and data type but in COMP-1 date is numeric and the data type is already pre-defined as one word floating form. 

Example:

Cobol




IDENTIFICATION DIVISION.
PROGRAM-ID. Comp1-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-VAL4  USAGE IS COMP-1.
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-1 USAGE DISPLAY'.
        MOVE 99 TO WS-VAL4.
    DISPLAY 'VALUE OF WS-VAL4 IS: ' WS-VAL4.
    DISPLAY 'LENGTH OF WS-VAL4: ' LENGTH OF WS-VAL4
    DISPLAY '                                       '
STOP RUN.


Output:

 

Explanation:

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



Last Updated : 08 Aug, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads