Question & Answer
Question
Within an Enterprise COBOL for z/OS program, how do I convert an item described as PICTURE X, which is EBCDIC on the mainframe, to ASCII?
Cause
Use the FUNCTION NATIONAL-OF and FUNCTION DISPLAY-OF. It is necessary to first convert it to Unicode. In the following example, WS-CCSID must match the code page of the data.
Answer
This simple example is for Enterprise COBOL on z/OS, not for COBOL on AIX. It only illustrates the FUNCTION NATIONAL-OF and FUNCTION DISPLAY-OF so it may not be complete enough for your application.
CBL DBCS,NSYMBOL(NATIONAL)
IDENTIFICATION DIVISION.
PROGRAM-ID. MAIN1.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-AREA PICTURE N(50).
01 WS-CCSID PICTURE 9(5).
01 WS-ASCII PICTURE X(50).
01 WS-EBCDIC PICTURE X(50).
PROCEDURE DIVISION.
MOVE "ABCDE"
TO WS-EBCDIC.
DISPLAY " WS-EBCDIC = " WS-EBCDIC.
MOVE FUNCTION NATIONAL-OF(WS-EBCDIC)
TO WS-AREA.
DISPLAY " WS-AREA = " WS-AREA.
MOVE 819 TO WS-CCSID.
MOVE FUNCTION DISPLAY-OF(WS-AREA, WS-CCSID)
TO WS-ASCII.
DISPLAY " WS-ASCII = " WS-ASCII.
DISPLAY "Now let's convert that WS-ASCII back to EBCDIC".
MOVE FUNCTION NATIONAL-OF(WS-ASCII,819 )
TO WS-AREA.
DISPLAY " WS-AREA = " WS-AREA.
MOVE 1140 TO WS-CCSID.
MOVE FUNCTION DISPLAY-OF(WS-AREA, WS-CCSID)
TO WS-EBCDIC.
DISPLAY " WS-EBCDIC = " WS-EBCDIC.
STOP RUN.
The EBCDIC letters ABCDE are hex C1C2C3C4C5. They will be converted to hex 4142434445. Then the 4142434445 will be converted back to C1C2C3C4C5.
Related Information
Was this topic helpful?
Document Information
Modified date:
08 August 2018
UID
swg21229962