In mainframe, 3 main character codings are used:
EBCDIC (native coding; IBM-037, IBM-1047 etc.)
UTF-8 (modern APIs, JSON, REST, MQ, Kafka messages, DB2 JSON fields)
UTF-16 (XML, Windows systems, NATIONAL fields)
COBOL has 2 main character types:
DISPLAY
NATIONAL
DISPLAY:
stored in EBCDIC
PIC X(n)
PIC 9(n)
PIC S9(n)
PIC A(n)
NATIONAL:
stored in UTF-16
PIC N(n)
PIC G(n)
unicode characters
COBOL convert between these automatically.
The JSON PARSE has built-in conversion function via the optional CONVERTING clause:
DISPLAY (JSON UTF-8 to COBOL DISPLAY, EBCDIC; default)
NATIONAL (JSON UTF-8 to COBOL NATIONAL, UTF-16)
The JSON GENERATE has built-in conversion function via the optional ENCODING clause:
UTF-8 (COBOL DISPLAY/NATIONAL to UTF-8; default)
UTF-16 (COBOL DISPLAY/NATIONAL to UTF-16)
The XML PARSE does not have dedicated clause, nor functionality, instead, in the handler procedure, via value assigning instructions, automatic COBOL conversion happens.
The XML GENERATE has conversion functionality via the optional ENCODING clause:
UTF-8 (COBOL DISPLAY/NATIONAL to UTF-8; default)
UTF-16 (COBOL DISPLAY/NATIONAL to UTF-16)
The Language Environment (LE) has character conversion routines:
CEECVRT (universal code conversion between EBCDIC, ASCII, UTF-8 and UTF-16)
CEEUTF8 (UTF8 to UTF-16)
CEEUTF16 (UTF-16 to UTF-8)
CEECVRT, the conversion-type can be:
UTF8 to UTF16
UTF16 to UTF8
EBCDIC to UTF8
UTF8 to EBCDIC
See LE character coding on the COBOL LANGUAGE ENVIRONMENT (LE) page.
EXAMPLE FOR USING CEECVRT: