Alphabetic Data Type


  • An alphabetic data type is used to declare the variables for storing and processing alphabetic strings.
  • It allows strings that are a combination of characters from 'A' to 'Z' or 'a' to 'z' and other allowed special characters.
  • It uses the character "A" as a PICTURE symbol to declare variables.
  • Each character in the string has to be counted to calculate the length, which should be coded after the PICTURE character "A". For Example - Declaring a variable to store a 3-character string should have the declaration as AAA or A(3).
  • An alphabetic variable can store maximum of 255 characters.

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 the above example, it is WS-VAR.
  • var-length - specifies the length of the string to store in the variable. The maximum length is 255 characters. From the above example, it is 10.
  • input-string - specifies the string assigned to the variable during the declaration. From the above example, it is MAINFRAMES.

Rules to Remember -

  • It should not code with any other data type.
  • USAGE DISPLAY is applicable for alphabetic data types. If no USAGE clause is coded, 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 is larger than the receiving variable size. For example – the variable declared with A(4) and the input data is "MAINFRAME", the variable contains only "MAIN".
  • If the input is smaller than the receiving variable size, unused character positions at the right are filled with SPACEs.
  • JUSTIFIED | JUST overrides the default justification and can justify the data to the right. Refer JUSTIFIED Clause for more information.

Practical Example -


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

Code -

----+----1----+----2----+----3----+----4----+----5----+
       ...
       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).
       ...
       PROCEDURE DIVISION. 
           MOVE "MAINFRAME SYSTEMS"   TO  WS-ALP-SVAR 
                                          WS-ALP-LVAR.

           DISPLAY "WS-ALP-SVAR (length - 10):  -" WS-ALP-SVAR "-".
           DISPLAY "WS-ALP-LVAR (Length - 20):  -" WS-ALP-LVAR "-". 
		   ...

Output -

WS-ALP-SVAR (length - 10):  -MAINFRAME -
WS-ALP-LVAR (Length - 20):  -MAINFRAME SYSTEMS   -
Note! In the above example, '-' is used to show the boundaries of the data.