A character-string value is a sequence of characters. The number of characters in a sequence is called the length of the sequence. In Open PL/I, the maximum length of a string value is 32767 bytes or characters.
A character-string of zero length is called a null string.
A character-string variable or character-string valued function is declared with the following attributes:
CHARACTER(n)
or
CHARACTER(n) VARYING
where n is an integer valued expression that specifies the maximum length of all string values that can be held by the variable or returned by the function.
The VARYING attribute causes the string variable or function to hold or return values of varying lengths. Internally, the length of the varying string is recorded along with the value. Varying strings are not padded to assume their maximum length, n. The representation of a varying string variable in storage is such that any string up to n characters may be held by the variable, and the length of the current string is retained as part of the value.
Without the VARYING attribute, a string variable or function always holds or returns values of length n. An assignment to a nonvarying string always extends short values with blanks on the right to make them n characters long.
Assignments of a string of more than n characters to either a VARYING or a nonvarying string variable cause only the leftmost n characters to be assigned and excess characters to be truncated.
Character-string values are compared from left to right using the collating sequence of the computer. Strings of unequal length are compared by effectively extending the shorter string with blanks on the right.
Nonvarying character-string variables always occupy exactly n bytes of storage. As elements of arrays or members of a structure, they begin on the next available byte and are not aligned on word or other storage address boundaries. This permits an array of nonvarying characters to be stored and accessed as if it were a single string. See the section Storage Sharing in the chapter Storage Classes.
Varying character-string variables always occupy n+2 bytes of storage. The first 2 bytes contain an integer L (0 <= L <= n) that specifies the length of the string value currently stored in the variable. The string text occupies the first L bytes of the storage following the 2 length bytes. The value of the last n–L bytes of the variable is undefined. The value L can be accessed using the LENGTH built-in function. An array of varying character strings cannot be accessed as if it were a single character string.
See the Open PL/I User's Guide for specific alignment of varying character strings.
A character-string constant is written in the following format:
'Any characters except quote'
If an apostrophe is required within the constant, it must be written as an adjacent pair of apostrophes.
Examples:
'ABC' 'He said, "I don"t know."' ''
In these examples, the second string displays a pair of single quotation marks used within the text string "don't". This text string also shows that the double quotation mark is insignificant as a delimiter of a character-string constant. The string in the last example is a null string.