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 NATIONAL sending operand and a USAGE UTF‑8 receiving operand, a MOVE statement 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-RECV

    NAT-SEND contains hex "0061006200630064" padded with hex "0020" (spaces). Upon execution of the last MOVE statement, UTF8-RECV contains 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 the DISPLAY‑OF intrinsic 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-RECV

    NAT-SEND contains hex "0061006200630064" padded with hex "0020" (spaces). Upon execution of the last MOVE statement, ALPHA-RECV contains hex "61626364" padded with hex "40" (EBCDIC spaces).

    Finally, converting UTF-8 to alphanumeric always requires use of the DISPLAY-OF intrinsic 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

Related references  
DISPLAY-OF (Enterprise COBOL for z/OS® Language Reference)