Alphanumeric Data Type with Justified Example


Scenario - Declaring alphabetic variables with RIGHT justification.

Code -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. ALPNUDTJ. 
       AUTHOR. MTH.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-VAR.
      * Variable with shorter length than passing data with justified
          05 WS-ALPN-SVAR  PIC X(10) JUSTIFIED RIGHT.
      * Variable with larger length with justified clause
          05 WS-ALPN-RVAR  PIC X(20) JUSTIFIED RIGHT.

       PROCEDURE DIVISION.

           MOVE "MAINFRAME SYSTEMS"   TO  WS-ALPN-SVAR 
                                          WS-ALPN-RVAR.

           DISPLAY "WS-ALPN-SVAR (LENGTH - 10): -" WS-ALPN-SVAR "-". 
           DISPLAY "WS-ALPN-RVAR (LENGTH - 20): -" WS-ALPN-RVAR "-".

           STOP RUN.

Output -

WS-ALPN-SVAR (LENGTH - 10): -ME SYSTEMS-            
WS-ALPN-RVAR (LENGTH - 20): -   MAINFRAME SYSTEMS-  

Explaining Example -

In the above example:

  • "MAINFRAME SYSTEMS" assigns to two alphanumeric variables, WS-ALPN-SVAR and WS-ALPN-LVAR, each with different lengths.
  • The string is moving from right to left (the rightmost character moves first because of default justification and leftmost characters are truncated) to the variables.
  • Last 10 characters moves to the variable to fit the size of WS-ALPN-SVAR and remaining characters truncated.
  • The input string completely moved into WS-ALPN-LVAR and the remaing characters filled with spaces at the left side.
  • Then, it displays the values of these variables and the program stops its execution.