UTF-8 groups

UTF-8 groups are specified with the GROUP-USAGE UTF-8 clause. These groups can contain fixed byte-length UTF-8 data items (items defined as PIC U BYTE-LENGTH n) or dynamic-length data items (items defined as PIC U DYNAMIC). Fixed character-length UTF-8 data items are not permitted. If the group contains only fixed byte-length UTF-8 data items then, in most cases, the group is processed as though it were redefined as an elementary category UTF-8 item described as PIC U BYTE-LENGTH m, where m is the total byte length of all items in the group.

For some operations on UTF-8 groups, however (just as for some operations on alphanumeric groups), group semantics apply. Such operations (for example, MOVE CORRESPONDING and INITIALIZE) recognize or process the elementary items within the UTF-8 group.

In use cases where the current limitation of UTF-8 groups is acceptable, that is, they can only contain fixed byte-length UTF-8 data items, UTF-8 groups provide several advantages for the processing of UTF-8 data compared to the processing of UTF-8 data within alphanumeric groups:

  • When you move a UTF-8 group to a longer data item that has USAGE UTF-8, the receiving item is padded with UTF-8 characters. By contrast, if you move an alphanumeric group that contains UTF-8 characters to a longer alphanumeric group that contains UTF-8 characters, alphanumeric spaces are used for padding. As a result, mishandling of data items could occur.
  • When you move a UTF-8 group to a shorter data item that has USAGE UTF-8, the UTF-8 group is truncated at UTF-8-character boundaries. By contrast, if you move an alphanumeric group that contains UTF-8 characters to a shorter alphanumeric group that contains UTF-8 characters, truncation might occur between the 2 bytes of a UTF-8 character.

USAGE UTF-8 groups: A group item can specify the USAGE UTF-8 clause at the group level as a convenient shorthand for the USAGE of each of the elementary data items within the group. Such a group is not a national group, but an alphanumeric group, and behaves in many operations, such as moves and compares, like an elementary data item of USAGE DISPLAY (except that no editing or conversion of data occurs).

Related references  
GROUP-USAGE clause (Enterprise COBOL for z/OS® Language Reference)