In any context in which you reference a character field, you can reference a substring, which is a sequential subset of the characters in that field. If a field value is ABCD, you can reference (for example) BC, which is the second and third character.
In addition, you can specify a substring on the left side of an assignment statement if the target field is of type CHAR, DBCHAR, or UNICODE. The substring area is filled (padded with blanks, if necessary), and the assigned text does not extend beyond the substring area (but is truncated, if necessary). In addition, you can specify a substring on the left side if the target field is a limited-length string; that situation is described later, by example.
The value of fromIndex represents a byte position unless itemReference refers to an item of type DBCHAR or UNICODE, in which case the value represents a double-byte character position.
When itemReference is a string (not limited length), the value of fromIndex is between 1 and the length of the string.
When itemReference is a limited-length string, the value of fromIndex is between 1 and the length you specified in the variable declaration. If the position has no value, the substring is an empty string, as shown in a later example.
Count from the leftmost character, even if you are working with a bidirectional language such as Arabic or Hebrew.
The value of toIndex represents a byte position unless itemReference refers to an item of type DBCHAR or UNICODE, in which case the value represents a double-byte character position.
When itemReference is a string (not limited length), the maximum value of toIndex is the position of the last character in the string.
When itemReference is a limited-length string, the maximum value of toIndexis the length specified in the variable declaration. If the position has no value, the substring extends only to the last position that holds a character, as shown in a later example.
If toIndex is greater than fromIndex and both numbers are valid, the substring is an empty string.
Count from the leftmost character, even if you are working with a bidirectional language such as Arabic or Hebrew.
limited string(20); s string; limited = "123456789"; s = limited[11:12]; // No error, and value of s is "" (an empty string). s = limited[8:12]; // No error, and value of s is "89". limited = s[8:12]; // Error because s has no length limit. // The last valid position is the one with the last character.
limited string(20) = "123456789"; s string = "abc"; limited[12:14] = s; // no error; value of limited becomes "123456789 abc":
Related concepts
References to variables in EGL
Related tasks
Syntax diagram for EGL statements and commands
Related reference
Text expressions