UCS-2 is a fixed-width 16-bit Unicode encoding covering the Basic Multilingual Plane. In COBOL, NATIONAL data (PIC N) is commonly stored as UCS-2 or UTF-16 depending on the compiler.
12345678910* NATIONAL data and conversion DATA DIVISION. WORKING-STORAGE SECTION. 01 WIDE-NAME PIC N(30). 01 DISP-NAME PIC X(60). PROCEDURE DIVISION. MOVE FUNCTION NATIONAL-OF("Jürgen Müller") TO WIDE-NAME MOVE FUNCTION DISPLAY-OF(WIDE-NAME) TO DISP-NAME DISPLAY "Name: " DISP-NAME STOP RUN.
12345678* Illustrative: writing NATIONAL data (compiler-specific details omitted) FD OUT-FILE. 01 OUT-REC. 05 OUT-NAME PIC N(30). PROCEDURE DIVISION. MOVE FUNCTION NATIONAL-OF("Álvaro") TO OUT-NAME * Ensure file/code-page settings match NATIONAL representation * Some systems require CODE-SET and explicit conversions.
Aspect | Description | Example |
---|---|---|
NATIONAL | PIC N | PIC N(30) |
Convert to NATIONAL | FUNCTION NATIONAL-OF | NATIONAL-OF("Café") |
Convert to DISPLAY | FUNCTION DISPLAY-OF | DISPLAY-OF(WIDE-NAME) |
1. What is UCS-2?
2. Which COBOL items commonly map to UCS-2?
3. Which functions convert between DISPLAY and NATIONAL text?
4. What should you consider when writing UCS-2 data to files?
5. Which is true of UCS-2 vs UTF-16?