Master Mainframe Technologies - COBOL, JCL, DB2, VSAM, CICS & More
ABEND Codes SQLCODEs File Status Interview Prep Contact
← Back to Data Division
Data Division | Beginner | COBOL

Alphanumeric Data

Problem Description

Work with alphanumeric (PIC X) and alphabetic (PIC A) data types.

Expected Output

String manipulation basics

Hints

PIC X allows any character, PIC A only letters and spaces.

Solution

IDENTIFICATION DIVISION. PROGRAM-ID. ALPHATEST. DATA DIVISION. WORKING-STORAGE SECTION. * Alphanumeric - any character allowed 01 WS-ALPHANUM PIC X(20) VALUE "Hello123!@#". * Alphabetic - only A-Z and space 01 WS-ALPHA PIC A(20) VALUE "Hello World". * Fixed length with VALUE 01 WS-NAME PIC X(10) VALUE "JOHN". * Will be padded: "JOHN " 01 WS-CODE PIC X(5). PROCEDURE DIVISION. DISPLAY "ALPHANUMERIC: [" WS-ALPHANUM "]". DISPLAY "ALPHABETIC: [" WS-ALPHA "]". DISPLAY "PADDED NAME: [" WS-NAME "]". MOVE "ABC" TO WS-CODE. DISPLAY "CODE: [" WS-CODE "]". * Right justify test MOVE SPACES TO WS-CODE. STRING "XY" DELIMITED SIZE INTO WS-CODE. DISPLAY "STRING: [" WS-CODE "]". STOP RUN.

Explanation:

PIC X=alphanumeric (any char), PIC A=alphabetic (letters/space only).