A string literal is a sequence of any characters that is enclosed in single quotes. In the literature, string literals are also called character strings; in this manual, however, the two terms are not identical: a character string does not need to be enclosed in single quotes. ABC, for example, is a character string, while ’ABC’ is a string literal.
A string literal may be represented in one of two ways, namely as C string or as an X string.
Data type | <c-string> | <x-string> |
Character set | All EBCDIC characters | Hexadecimal digits (0 ... F) |
Length | Freely selectable | Freely selectable |
Representation | [C]'.......' | X'......' |
Null string | [C]'' | X'' |
Note
Internally, C strings and X strings are represented identically, which means that a C string can also be represented as an X string.
The terms C string and X string refer to how the bytes comprising the character string are represented:
In a C string, each byte is represented by its EBCDIC character (C stands for “character”). Consequently, its character set is the entire EBCDI code; this also means that uppercase and lowercase are retained.
In an X string, each byte is represented by the resulting EBCDIC character half-bytes; thus, the X string contains a sequence of paired representations of the left and right half-bytes. Consequently, its character set is the digits of the hexadecimal number system, i.e. the digits from 0 to F.
If an odd number of hexadecimal digits is specified for an X string, the string is filled internally from the left with zeros. (Example: X’123’ becomes X’0123’.)
The null string constitutes a special case. It contains pairs of single quotes only, which can follow a C or X (C’’/X’’). The null string must not be confused with a space string (C’
Strings are always enclosed in single quotes; at the same time, any character strings or numbers that are enclosed in single quotes are interpreted as strings.
If the single quote is not preceded by a character, the string is normally considered to be a C string. An X string must be preceded by an X. Other letters are not allowed and result in an error.
Strings can be linked together by means of relational operators or concatenation operators. Strings can also be inserted in a new expression as the contents of a variable, as a result of a function call or as a result of an expression.
Note
The designation “string_expression“, used as a parameter value in predefined functions, stands for any of the following values:
a string enclosed in quotes (<c-string>)
the name of a variable containing a string (<composed-name>)
an expression that returns a string as result
Example
/JV-NAME = 'MY-JV' /MY-VAR = JV('JV-NAME') value of the job variable JV-NAME /MY-VAR = JV(JV-NAME) value of the job variable MY-JV /MY-VAR = JV('&JV-NAME') value of the job variable MY-JV /MY-VAR = JV(JV(JV-NAME)) value of the job variable whose name is stored in job variable MY-JV
Example
/A = 'ABCD' /B = C'ABCD' /C = X'C1C2C3C4'
The variables A and B are assigned the same C string, while variable C is assigned an X string that yields the string ABCD when evaluated. All three variables thus have identical contents.