Null-terminated alphanumeric literals

Alphanumeric literals can be null-terminated.

The format for null-terminated alphanumeric literals is:

Format 4: Null-terminated alphanumeric literals

Z"mixed-characters"
Z'mixed-characters'
Z" or Z'
The opening delimiter for a null-terminated alphanumeric literal. Both characters of the opening delimiter (Z" or Z') must be on the same source line.
" or '
The closing delimiter for a null-terminated alphanumeric literal.

If a quotation mark is used in the opening delimiter, a quotation mark must be used as the closing delimiter. Similarly, if an apostrophe is used in the opening delimiter, an apostrophe must be used as the closing delimiter.

mixed-characters
Can be any of the following characters:
  • Solely single-byte characters
  • Mixed single-byte and DBCS characters
  • Solely DBCS characters

However, you cannot specify the single-byte character with the value X'00'. X'00' is the null character automatically appended to the end of the literal. The content of the literal is otherwise subject to the same rules and restrictions as an alphanumeric literal with DBCS characters (format 2).

The length of the string of characters in the literal content can be 0 to 159 bytes. The actual length of the literal includes the terminating null character, and is a maximum of 160 bytes.

A null-terminated alphanumeric literal has data class and category alphanumeric. It can be used anywhere an alphanumeric literal can be used except that null-terminated literals are not supported in ALL literal figurative constants.

The LENGTH intrinsic function, when applied to a null-terminated alphanumeric literal, returns the number of bytes in the literal prior to but not including the terminating null. (The LENGTH special register does not support literal operands.)