Displaying a Substring of a Character String Variable
The ILE source debugger does not support the reference modification
syntax of ILE COBOL. Instead, you can use the %SUBSTR operator with the EVAL
command to display a substring of a character string variable. The %SUBSTR
operator obtains the substring of a character string variable from a starting
element position for some number of elements.
Note: The ILE source
debugger does not support COBOL's reference modification syntax for
handling substrings. You need to use the %SUBSTR operator of the ILE source
debugger to handle substrings.
The syntax for the %SUBSTR operator is as follows:
%SUBSTR(identifier start-element number-of-elements)where identifier must be a character string variable, and start-element and number-of-elements must be non-zero, positive
integer literals. identifier can be a qualified, subscripted, or
indexed variable. start-element + number-of-elements - 1 cannot be
greater than the total number of elements in identifier.For example, you can obtain the first 10 elements of a 20-element character string by using %SUBSTR(char20 1 10). You can obtain the last 5 elements of a 8-element character string by using %SUBSTR(char8 4 5). In the case of a DBCS or DBCS-edited item, element refers to a DBCS character (in other words, a two-byte character).
You can use the %SUBSTR operator to assign a substring of a character string
variable to another variable or substring of a variable. Data is copied from
the source variable to the target variable from left to right. When the source
or target variables or both are substrings, then the operand is the substring
portion of the character string variable, not the entire character string
variable. When the source and target variable are of different sizes, then
the following truncation and padding rules apply:
- If the length of the source variable is greater than the length of the target variable, the character string is truncated to the length of the target variable.
- If the length of the source variable is less than the length of the target variable, the character string is left justified in the target variable and the remaining positions are filled with blanks.
- If the length of the source variable is equal to the length of the target variable, the two variables will be exact copies of one another after the assignment.
Note: It is possible to use a substring of the same character
string variable in both the source variable and the target variable; however,
if any portion of the target string overlaps the source string, an error will
result.
Figure 1 shows some example of how the %SUBSTR operator can be used.
Evaluate Expression
Previous Debug expressions
> EVAL CHAR10
CHAR10 = '10CHARLONG'
> EVAL CHARA
CHARA = 'A'
> EVAL CHARA = %SUBSTR(CHAR10 3 5)
CHARA = 'C'
> EVAL %SUBSTR(CHAR10 1 2) = 'A'
CHAR10 = 'A CHARLONG'
> EVAL %SUBSTR(CHAR10 1 2) = 'XYZ'
CHAR10 = 'XYCHARLONG'
> EVAL %SUBSTR(CHAR10 7 4) = 'ABCD'
CHAR10 = 'XYCHARABCD'
> EVAL %SUBSTR(CHAR10 1 2) = %SUBSTR(CHAR10 7 4)
CHAR10 = 'ABCHARABCD'
Bottom
Debug . . . _________________________________________________________________
_______________________________________________________________________________
F3=Exit F9=Retrieve F12=Cancel F19=Left F20=Right F21=Command entry