Alphabetic Data Type with Justified Example


Scenario - Declaring alphabetic variables with RIGHT justification.

Code -

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

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

       PROCEDURE DIVISION.

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

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

           STOP RUN.

Output -

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

Explaining Example -

In the above example:

  • "MAINFRAME SYSTEMS" assigns to two alphabetic variables, WS-ALPA-SVAR and WS-ALPA-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-ALPA-SVAR and remaining characters truncated.
  • The input string completely moved into WS-ALPA-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.