Alphabetic Data Type Example


Scenario - Declaring alphabetic variables, and explaining the data truncation.

Code -

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

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-VAR.
      * Variable with shorter length than passing data
          05 WS-ALP-SVAR   PIC A(10).
      * Variable with larger length
          05 WS-ALP-LVAR   PIC A(20).

       PROCEDURE DIVISION.

           MOVE "MAINFRAME SYSTEMS"   TO  WS-ALP-SVAR 
                                          WS-ALP-LVAR.

           DISPLAY "WS-ALP-SVAR:  -" WS-ALP-SVAR "-". 
           DISPLAY "WS-ALP-LVAR:  -" WS-ALP-LVAR "-". 

           STOP RUN.

Output -

WS-ALP-SVAR (length - 10):  -MAINFRAME -
WS-ALP-LVAR (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 left to right (the leftmost character moves first because of default justification and rightmost characters are truncated) to the variables.
  • First 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 right side.
  • Then, it displays the values of these variables and the program stops its execution.