IBM AS/400 Frozen Dessert Maker User Manual


 
Stepping Through the Program Object
The %SUBSTR built-in function allows you to substring a string variable. The first
parameter must be a string identifier, the second parameter is the starting position,
and the third parameter is the number of single-byte or double-byte characters. In
addition. the second and third parameters must be positive, integer literals. Param-
eters are delimited by one or more spaces.
Use the %SUBSTR built-in function to:
Display a portion of a character field
Assign a portion of a character field
Use a portion of a character field on either side of a conditional break
expression.
Figure 102 shows some examples of the use of %SUBSTR based on the source in
Figure 105 on page 212.
> EVAL String
STRING = 'ABCDE '
** Display the first two characters of String **
> EVAL %substr (String 1 2)
%SUBSTR (STRING 1 2) = 'AB'
> EVAL TableA
TABLEA = 'aaa'
** Display the first character in the first table element **
> EVAL %substr(TableA 1 1)
%SUBSTR(TABLEA 1 1) = 'a'
> EVAL BigDate
BIGDATE = '1994-10-23'
** Set String equal to the first four characters of BigDate **
> EVAL String=%substr(BigDate 1 4)
STRING=%SUBSTR(BIGDATE 1 4) = '1994 '
> EVAL Fld1 (5 characters)
FLD1 = 'ABCDE'
> EVAL String (6 characters)
STRING = '123456'
** Set the characters 2-5 of String equal to the
first four characters of Fld1 **
> EVAL %substr(String 2 4) = %substr(Fld1 1 4)
%SUBSTR(STRING 2 4) = %SUBSTR(FLD1 1 4) = 'ABCD'
> EVAL String
STRING = '1ABCD6'
** You can only use %SUBSTR on character or graphic strings! **
> EVAL %substr (Packed1D0 1 2)
String type error occurred.
Figure 102. Examples of %SUBSTR using DBGEX
To change the current index, you can use the %INDEX built-in function, where the
index is specified in parentheses following the function name. An example of
%INDEX is found in the table section of Figure 99 on page 203 and Figure 100 on
page 204.
Note: %INDEX will change the current index to the one specified. Therefore, any
source statements which refer to the table or multiple-occurrence data struc-
ture subsequent to the EVAL statement may be operating with a different
index than expected.
Chapter 11. Debugging Programs 207