Converting national to UTF-8 and UTF-8 to alphanumeric (DISPLAY-OF)
You can use one of the two methods described in this topic to convert a national to UTF- 8, depending on the sending operand.
About this task
- When you use a
USAGE NATIONALsending operand and aUSAGE UTF‑8receiving operand, aMOVEstatement automatically converts the data from UTF‑8 to national.For example:01 NAT-SEND PIC N(100). 01 UTF8-RECV PIC U(100). ... MOVE N"abcd" TO NAT-SEND MOVE NAT-SEND TO UTF8-RECVNAT-SENDcontains hex "0061006200630064" padded with hex "0020" (spaces). Upon execution of the lastMOVEstatement,UTF8-RECVcontains hex "61626364" padded with hex "20" (spaces). - When you store UTF‑8 data at runtime in an alphanumeric item (
USAGE DISPLAY), you can use a national sending operand (USAGE NATIONAL) and an alphanumeric receiving operand (USAGE DISPLAY) and invoke theDISPLAY‑OFintrinsic function to convert the data to UTF‑8 format.For example:01 NAT-SEND PIC N(100). 01 ALPHA-RECV PIC X(100). ... MOVE N"abcd" TO NAT-SEND MOVE FUNCTION DISPLAY-OF(NAT-SEND 1208) TO ALPHA-RECVNAT-SENDcontains hex "0061006200630064" padded with hex "0020" (spaces). Upon execution of the lastMOVEstatement,ALPHA-RECVcontains hex "61626364" padded with hex "40" (EBCDIC spaces).Finally, converting UTF-8 to alphanumeric always requires use of the
DISPLAY-OFintrinsic function.For example:01 UTF8-SEND PIC U(100). 01 ALPHA-SEND PIC X(100). 01 ALPHA-RECV PIC X(100). ... MOVE FUNCTION DISPLAY-OF(UTF8-SEND 1140) TO ALPHA-RECV MOVE FUNCTION DISPLAY-OF(ALPHA-SEND 1140) TO ALPHA-RECV