Changing the Value of Fields
You can change the value of fields by using the EVAL command with an assignment operator (=).
The scope of the fields used in the EVAL command is defined by using the QUAL command. However, you do not need to specifically define the scope of the fields contained in an ILE RPG module because they are all of global scope.
EVAL field-name = value
on
the debug command line. field-name is the name of the variable that
you want to change and value is an identifier, literal, or constant
value that you want to assign to variable field-name. For example,
EVAL COUNTER=3
changes the value of COUNTER to 3 and shows
COUNTER=3 = 3
on the message line of the Display Module Source display.Use the EVAL debug command to assign numeric, alphabetic, and alphanumeric data to fields. You can also use the %SUBSTR built-in function in the assignment expression.
- If the length of the source expression is less than the length of the target expression, then the data is left justified in the target expression and the remaining positions are filled with blanks.
- If the length of the source expression is greater than the length of the target expression, then the data is left justified in the target expression and truncated to the length of the target expression.
- Another graphic field
- A graphic literal of the form G'oK1K2i'
- A hexadecimal literal of the form X'hex digits'
UCS-2 fields must be changed using hexadecimal constants. For example, since %UCS2('AB') = U'00410042', then to set a UCS-2 field to the UCS-2 form of 'AB' in the debugger, you would use EVAL ucs2 = X'00410042'.
Variable-length fields can be assigned using, for example, EVAL varfldname = 'abc'. This sets the data part of the field to 'abc' and the length part to 3.
- Character literals should be in quotes.
- Graphic literals should be specified as G'oDDDDi', where o is shift-out and i is shift-in.
- Hexadecimal literals should be in quotes, preceded by an 'x'.
- Numeric literals should not be in quotes.
EVAL FLD1 = 3
EVAL _QRNU_NULL_FLD1 = '0'
EVAL SUBF2 = 5
EVAL _QRNU_NULL_SUBF2 = '0'
EVAL ARR(3) = 0
EVAL _QRNU_NULL_ARR(3) = '1'
EVAL DS3.INFO(2).SUB4 = 'some value'
EVAL _QRNU_NULL_DS3.INFO(2).SUB4 = '0'
For more information on debugging
null-capable fields, see Displaying Null-Capable Fields.Figure 1 shows some examples of changing field values based on the source in Figure 1. Additional examples are also provided in the source debugger online help.
** Target Length = Source Length **
> EVAL String='123456' (6 characters)
STRING='123456' = '123456'
> EVAL ExportFld (6 characters)
EXPORTFLD = 'export'
> EVAL String=ExportFld
STRING=EXPORTFLD = 'export'
** Target Length < Source Length **
> EVAL String (6 characters)
STRING = 'ABCDEF'
> EVAL LastName (10 characters)
LASTNAME='Williamson' = 'Williamson'
> EVAL String=LastName
STRING=LASTNAME = 'Willia'
** Target Length > Source Length **
> EVAL String (6 characters)
STRING = '123456'
> EVAL TableA (3 characters)
TABLEA = 'aaa'
> EVAL String=TableA
STRING=TABLEA = 'aaa '
** Using %SUBSTR **
> EVAL BigDate
BIGDATE = '1994-10-23'
> EVAL String=%SUBSTR(BigDate 1 4)
STRING=%SUBSTR(BIGDATE 1 4) = '1994 '
** Substring Target Length > Substring Source Length **
> EVAL string = '123456'
STRING = '123456' = '123456'
> EVAL LastName='Williamson'
LASTNAME='Williamson' = 'Williamson'
> EVAL String = %SUBSTR(Lastname 1 8)
STRING = %SUBSTR(LASTNAME 1 8) = 'Willia'
** Substring Target Length < Substring Source Length **
> EVAL TableA
TABLEA = 'aaa'
> EVAL String
STRING = '123456'
> EVAL String=%SUBSTR(TableA 1 4)
Substring extends beyond end of string. ** Error **
> EVAL String
STRING = '123456'