Summary -

In this topic, we described about the Alpha-numeric Data Type with detailed example.

Alphanumeric data type allows to declare the data items to store the strings that are combination of alphabets and numbers. Alphanumeric strings are the combination of A to Z or a to z characters or 0 to 9 numbers and other allowed special characters.

The list of allowed characters are specified below -

Character(s) Description
+Plus sign
-Minus sign or hyphen
/Forward slash or solidus
=Equal sign
$Currency sign
.Decimal point or period
"Quotation mark
(Left parenthesis
)Right parenthesis
>Greater than
<Less than
A - ZAlphabet (uppercase)
a - zAlphabet (lowercase)
0 - 0Numeric

Alphanumeric data type uses character ‘X’ in PICTURE clause of data description to represent the alphanumeric 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 XXX or X(3).

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

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

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

Alignment / Justification -

Alphanumeric data type is left justified by default and the data in all alphanumeric 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 Alphanumeric type. Learn more about JUSTIFIED clause.

Practical Example -

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

Code -

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

Output -

Alphanumeric Data Type program Output