Alphabetic Data Type


The alphabetic data type is used to declare the variables for processing the alphabetic strings. Alphabetic strings are the combination of "A" to "Z" or "a" to "z" characters and other allowed special characters.

Alphabetic data type uses the character "A" with a PICTURE clause to declare variables. Each character in the string has to be counted and should be part of the length followed by the data type character "A". For Example - Declaring a variable to store 3-character string should have the declaration as AAA or A(3).

The list of allowed characters are -

Character(s) Description
Space
+Plus sign
-Minus sign or hyphen
*Asterisk
/Forward slash or solidus
=Equal sign
$Currency sign
,Comma
;Semicolon
.Decimal point or period
Character(s) Description
"Quotation mark
'Apostrophe
(Left parenthesis
)Right parenthesis
>Greater than
<Less than
:Colon
_Underscore
A - ZAlphabet (uppercase)
a - zAlphabet (lowercase)

Syntax -

----+----1----+----2----+----3----+----4----+----5----+
       01 ws-variable      PIC A(var-length) 
	                      [VALUE "input-string"].
Note! All statements coded in [ ] are optional.

Example -

01 WS-VAR      PIC A(10) VALUE "MAINFRAMES".
  • ws-variable - specifies the variable name. From example, it is WS-VAR.
  • var-length - specifies the length of the string to store in the variable. The maximum length is 256 characters. From example, it is 10.
  • input-string - specifies the string assigned to the variable during the declaration. From example, it is MAINFRAMES.

Rules -

  • Alphabetic data types should not be coded with any other data types.
  • USAGE DISPLAY is only applicable for alphabetic data types. If no USAGE clause is coded during the declaration, DISPLAY is applied. i.e., 1 character = 1 byte.

Alignment | Justification -


  • The alphabetic data type is left justified by default, and the data in all alphabetic variables are left justified automatically.
  • The rightmost characters are truncated if the input data is larger than the variable size. For example – the variable declared with A(4) and the input data is "MAINFRAME", the variable contains only "MAIN".
  • Suppose the input data is smaller than the receiving variable. In that case, the unused character positions at the right are filled with spaces.
  • JUSTIFIED | JUST overrides the default justification of alphabetic data type. Refer JUSTIFIED Clause for more information.

Practical Example -


Scenario - Example describes the alphabetic variable declaration, justification, and 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 the passing input data
          05 WS-ALP-SVAR   PIC A(10).
	  * Variable with larger length than the passing input data
          05 WS-ALP-LVAR   PIC A(20).
	  * Variable with larger length with JUSTIFIED clause
          05 WS-ALP-RVAR   PIC A(20) JUSTIFIED RIGHT.

       PROCEDURE DIVISION. 
           MOVE "MAINFRAME SYSTEMS"   TO  WS-ALP-SVAR 
                                          WS-ALP-LVAR 
                                          WS-ALP-RVAR.
  
           DISPLAY "WS-ALP-SVAR:  -" WS-ALP-SVAR "-".
           DISPLAY "WS-ALP-LVAR:  -" WS-ALP-LVAR "-". 
           DISPLAY "WS-ALP-RVAR:  -" WS-ALP-RVAR "-". 
 
           STOP RUN.

Output -

WS-ALP-SVAR:  -MAINFRAME -
WS-ALP-LVAR:  -MAINFRAME SYSTEMS   -
WS-ALP-RVAR:  -   MAINFRAME SYSTEMS-
Note! In the above example, '-' is used to show the boundaries of the data.