Summary -

In this topic, we described about the Alphabetic Data Type with detailed example.

Alphabetic data type allows to declare the data items to store the alphabetic strings. Alphabetic strings are the combination of A to Z or a to z characters and other allowed special characters.

The list of allowed characters are specified below -

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
"Quotation mark
'Apostrophe
(Left parenthesis
)Right parenthesis
>Greater than
<Less than
:Colon
_Underscore
A - ZAlphabet (uppercase)
a - zAlphabet (lowercase)

Alphabetic data type uses character "A" in PICTURE clause of data description to represent the alphabetic characters. Each character in the string should have counted and specified with data type definition using PICTURE clause.

For example - Declaring a data item to store 3-character string should have the declaration as AAA or A(3).

The alphabetic data type maximum length is 256 or can code up to 256 characters in the PICTURE clause (A(256)) using the default compiler option.

Alphabetic data type can’t code with a combination of other data types. DISPLAY USAGE clauses are applicable for alphabetic data type.

If no USAGE clause specified during the declaration, DISPLAY computation applied to the declaration. i.e., 1 character = 1 byte.

Alignment / Justification -

Alphabetic data type is left justified by default and the data in all alphabetic data items or variables are left justified automatically.

If the sending data is larger than the receiving data item, the rightmost characters are truncated.

If the sending data is smaller than the receiving data item, the unused character positions at the right are filled with spaces.

JUSTIFIED / JUST clause is used to override the default justification of alphabetic type. Learn more about JUSTIFIED clause.


Practical Example -

Scenario - Below example describes about the alphabetic data type declaration, justification and truncation in COBOL programming.

Code -

Alphabetic Data Type program Code
=COLS> ----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
****** ***************************** Top of Data ******************************
000001        IDENTIFICATION DIVISION.                                         
000002        PROGRAM-ID. ALPHADT.                                             
000003        AUTHOR. MTH.                                                     
000004                                                                         
000005        DATA DIVISION.                                                   
000006        WORKING-STORAGE SECTION.                                         
000007                                                                         
000008        01 WS-ALP-SVAR   PIC A(10).                                      
000009        01 WS-ALP-LVAR   PIC A(20).                                      
000010                                                                         
000011        PROCEDURE DIVISION.                                              
000012                                                                         
000013            MOVE "MAINFRAME SYSTEMS"   TO  WS-ALP-SVAR                   
000014                                           WS-ALP-LVAR.                  
000015                                                                         
000016            DISPLAY "WS-ALP-SVAR:  -" WS-ALP-SVAR "-".                   
000017            DISPLAY "WS-ALP-LVAR:  -" WS-ALP-LVAR "-".                   
000018                                                                         
000019            STOP RUN.                                                    
****** **************************** Bottom of Data ****************************

Output -

Alphabetic Data Type program Output