Open In App

Data Type Justification in COBOL

Data Classification/Types helps the system identify how the programmer wants to use the data in any particular program. In COBOL we have three different Classifications of DATA TYPES, which are Numeric, Alphabetic, and Alpha-Numeric data types.

In COBOL DATA TYPE justification applies to Numeric data type, Alpha-numeric data type, and Alphabetic data type. Among which Numeric Data Type will come under right justified whereas Alphabetic/Alpha-Numeric data type will come under left justified.



Numeric Justification:

If the input data is numbers or digits then it will come under Numeric data types. In COBOL we will use the Numeric data type by using the ‘9(x)’ where x can be any integer, which will represent the size of the data. The maximum value of the numeric data type will be 9(18). The value of numeric justification will get assigned from right to left.  



Alphabetic Justification :

If the input data is alphabetic then it will come under alphabetic data types. In COBOL we will assign the ALPHABETIC DATA TYPE by using ‘A(x)’ where x can be any integer, which will represent the size of the taken data. The maximum size will be A(35535) in COBOL ALPHABETIC DATA TYPE. The value of ALPHABETIC DATA TYPE will get assigned from left to right.

Alpha-Numeric Justification:

If the input data is a mixture of alphabetic and numeric digits then it will come under ALPHA-NUMERIC DATA TYPE. In COBOL we will assign the ALPHA-NUMERIC DATA TYPE by using ‘X(x)’ where x can be any integer, which will represent the size of the taken data. The maximum size will be X(35535) in COBOL ALPHA-NUMERIC DATA TYPE. The value of ALPHA-NUMERIC DATA TYPE will also get assigned from left to right.

Example:




IDENTIFICATION DIVISION.
PROGRAM-ID. DATATYPES.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 VAR011 PIC 9(10) .
01 VAR012 PIC 9(5).
01 VAR021 PIC A(15) .
01 VAR022 PIC A(5).
01 VAR031 PIC X(20) .
01 VAR032 PIC X(13).
PROCEDURE DIVISION.
MAIN-PARA.
    MOVE '123456789' TO VAR011.
    MOVE '123456789' TO VAR012.
    DISPLAY 'NUMERIC DATA JUSTIFICATION'.
    DISPLAY 'VAR011 : ' VAR011.
    DISPLAY 'VAR012 : ' VAR012.
    MOVE 'ABCDEFGHIJKL' TO VAR021.
    MOVE 'ABCDEFGHIJKL' TO VAR022.
    DISPLAY 'ALPHABETIC DATA JUSTIFICATION'.
    DISPLAY 'VAR021 : ' VAR021.
    DISPLAY 'VAR022 : ' VAR022.
    MOVE 'GEEKSFORGEEKS12345' TO VAR031.
    MOVE 'GEEKSFORGEEKS12345' TO VAR032.
    DISPLAY 'ALPHA-NUMERIC DATA JUSTIFICATION'.
    DISPLAY 'VAR031 : ' VAR031.
    DISPLAY 'VAR032 : ' VAR032.
STOP RUN.

Output: 

 

Explanation :  

In the result, we can see two different scenarios for all the data types:


Article Tags :