Converting UTF-8 to national (NATIONAL-OF)

You can use one of the two methods described in this topic to convert a UTF-8 data item to a national data item.

About this task

  • When a UTF-8 item (USAGE UTF-8) is used as the sender and a national item is used as the receiver, the MOVE statement converts automatically. Do not use the NATIONAL-OF intrinsic function.
    For example:
    
    01 UTF8-SEND PIC U(100).
    
    01 NAT-RECV PIC N(100).
    
    ...
    
    MOVE "abcd" TO UTF8-SEND
    
    MOVE UTF8-SEND TO NAT-RECV

    UTF8-SEND contains hex "61626364" padded by hex "20" (spaces). Upon execution of the last MOVE statement, NAT-RECV contains hex "0061006200630064" padded by hex "0020" (spaces).

  • When UTF-8 data is stored in an alphanumeric item at runtime, use the NATIONAL-OF intrinsic function to convert the data to a national item.
    For example:
    
    01 ALPHA-SEND PIC X(100).
    
    01 NAT-RECV PIC N(100).
    
    ...
    
    MOVE X"61626364" TO ALPHA-SEND
    
    MOVE FUNCTION NATIONAL-OF(ALPHA-SEND(1:4) 1208) TO NAT-RECV

    ALPHA-SEND(1:4) contains hex "61626364". Upon execution of the last MOVE statement, NAT-RECV contains hex "0061006200630064" padded by hex "0020" (spaces).

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