The following example shows the NATIONAL-OF and DISPLAY-OF intrinsic functions and the MOVE statement for converting to and from national (UTF-16) data items. It also demonstrates the need for explicit conversions when you operate on strings that are encoded in multiple code pages.
* . . .
01 Data-in-Unicode pic N(100) usage national.
01 Data-in-Greek pic X(100).
01 other-data-in-US-English pic X(12) value “PRICE in $ =”.
* . . .
Read Greek-file into Data-in-Greek
Move function National-of(Data-in-Greek, “IBM-1253”)
to Data-in-Unicode
* . . . process Data-in-Unicode here . . .
Move function Display-of(Data-in-Unicode, “IBM-1253”)
to Data-in-Greek
Write Greek-record from Data-in-Greek
The example above works correctly because the input code page is specified. Data-in-Greek is converted as data represented in IBM-1253 (ASCII Greek). However, the following statement results in an incorrect conversion unless all the characters in the item happen to be among those that have a common representation in both the Greek and the English code pages:
Move Data-in-Greek to Data-in-Unicode
Assuming that the locale in effect is en_US.IBM-1252, the MOVE statement above converts Data-in-Greek to Unicode based on the code page IBM-1252 to UTF-16LE conversion. This conversion does not produce the expected results because Data-in-Greek is encoded in IBM-1253.
If you set the locale to el_GR.IBM-1253 (that is, your program handles ASCII data in Greek), you can code the same example correctly as follows:
* . . .
01 Data-in-Unicode pic N(100) usage national.
01 Data-in-Greek pic X(100).
* . . .
Read Greek-file into Data-in-Greek
* . . . process Data-in-Greek here ...
* . . . or do the following (if need to process data in Unicode):
Move Data-in-Greek to Data-in-Unicode
* . . . process Data-in-Unicode
Move function Display-of(Data-in-Unicode) to Data-in-Greek
Write Greek-record from Data-in-Greek
related tasks
Setting the locale