The EVAL operation code evaluates an assignment statement of the
form "result = expression" or "result
op = expression". The expression is evaluated and the result
placed in result. Therefore, result cannot
be a literal or constant but must be a field name, array name, array
element, data structure, data structure subfield, or a string using
the %SUBST built-in function.
The expression may yield any of the RPG data types. The type of
the expression must be the same as the type of the result. A character,
graphic, or UCS-2 result will be left justified and padded with blanks
on the right or truncated as required. If result is
a variable-length field, its length will be set to the length of the
result of the expression.
If the result represents an unindexed array or an array specified
as array(*), the value of the expression is assigned to each element
of the result, according to the rules described in Specifying an Array in Calculations.
Otherwise, the expression is evaluated once and the value is placed
into each element of the array or sub-array. For numeric expressions,
the half-adjust operation code extender is allowed. The rules for
half adjusting are equivalent to those for the arithmetic operations.
On a free-form calculation specification, the operation
code name may be omitted if no extenders are needed, and if the variable
does not have the same name as an operation code.
For the assignment operators +=, -=, *=, /=, and **=,
the appropriate operation is applied to the result and the expression,
and the result is assigned to the result. For example, statement X+=Y
is roughly equivalent to X=X+Y. The difference between the two statements
is that for these assignment operators, the result operand is evaluated
only once. This difference is significant when the evaluation of the
result operation involves a call to a subprocedure which has side-effects,
for example:
warnings(getNextCustId(OVERDRAWN)) += 1;
See Expressions for general information on expressions.
See Precision Rules for Numeric Operations for information on precision rules for numeric
expressions. This is especially important if the expression contains
any divide operations, or if the EVAL uses any of the operation extenders.