EVAL-CORR (Assign corresponding subfields)

Free-Form Syntax EVAL-CORR{(HMR)} target = source;
Code Factor 1 Extended Factor 2
EVAL-CORR   target = source
The EVAL-CORR operation assigns data and null-indicators from the corresponding subfields of the source data structure to the subfields of the target data structure. The subfields that are assigned are the subfields that have the same name and compatible data type in both data structures. For example, if data structure DS1 has character subfields A, B, and C, and data structure DS2 has character subfields B, C, and D, statement
EVAL-CORR DS1 = DS2
will assign data from subfields DS2.B and DS2.C to DS1.B and DS1.C. Null-capable subfields in the target data structure that are affected by the EVAL-CORR operation will also have their null-indicators set from the null-indicator from the source data structure's subfield, or to *OFF, if the source subfield is not null-capable.

If an operation code extender H is specified, the half-adjust function applies on all numeric assignments. Extenders for EVAL-CORR can be specified only in Free-form calculations.

If operation code extender M or R is specified, it applies to the arguments of any procedure call specified as part of the source or target expression. Extenders for EVAL-CORR can be specified only in Free-form calculations.

The EVAL-CORR Summary section in the compiler listing can be used to determine
  • which subfields were selected to be affected by the EVAL-CORR operation
  • for subfields not selected, the reason the subfield was not selected
  • for subfields that are selected, any additional information about the subfields such as a difference in the dimension or null-capability of the subfields.

See the Rational Development Studio for i: ILE RPG Programmer's Guide for more information about the EVAL-CORR Summary section.

Remember the following when using the EVAL-CORR operation:
  • Operation code EVAL-CORR may be coded either in free-form calculations or in fixed-form calculations. When coded in fixed-form calculations, the assignment expression is coded in the Extended Factor 2 entry, with the Factor 1 entry left blank.
  • The source and target operands must both be data structure variables, including data structure subfields defined with LIKEDS or LIKEREC.
  • The operands may be qualified or unqualified data structures. However, for the operation to be successful, at least one of the operands must be a qualified data structure; otherwise, it would not be possible for the two data structures to have any subfields with the same name.
  • The subfields involved in the assignment are those that have the same name in both data structures and have data types that are compatible for assignment using EVAL.
  • When comparing the subfield names to find corresponding subfieds, the names used are the internal program names; the internal program names may be different from the external names in the case of fields from externally-described files or data structures. For fields defined externally and renamed or prefixed, the name used is the name after applying the rename or prefix.
  • For subfields in the source and target that correspond by name and are both data structures defined with LIKEDS or LIKEREC, the subfields that are assigned are the corresponding subfields of the subfield data structures. If two subfields in the source and target have the same name but one is a data structure defined with LIKEDS or LIKEREC, and the other is not a data structure, the subfield is not assigned by the EVAL-CORR operation.
  • The assignment of data from the source subfields to the target subfields follows the same rules as for operation code EVAL. For example, character values are assigned left adjusted with truncation or padding with blanks for unequal lengths.
  • Data is assigned subfield by subfield by the order of subfields in the source data structure. If there are overlapping subfields in the target data structure, either due to overlapping from-and-to positions or due to the OVERLAY keyword, later assignment may overwrite earlier moves.
  • When the source and target data structures or corresponding source and target subfields which are both data structures are defined the same way with LIKEDS or LIKEREC, that is, both data structures are defined like the same data structure, the compiler will optimize the assignment and assign the data structure as a whole, and not as a series of individual subfield assignments.
  • If either the source or target operand is a multiple occurrence data structure, the current occurrence is used.
  • If you are working with arrays:
    • If the source operand is an unindexed array data structure, the target data structure must also be an array data structure.
    • If the target operand is an unindexed array data structure, the operation works on each element of the array data structure, following the same rules as EVAL with an array result. %SUBARR may be used to restrict the number of elements used in either the source or target data structure array.
    • If one subfield is an array, both subfields must be arrays. If the dimension of one array subfield is smaller than the other, only the smaller number of array elements is assigned. If the target subfield has more elements, the additional elements are unchanged by the EVAL-CORR operation.
  • If you are working with null-capable subfields:
    • EVAL-CORR automatically handles assignment of null-indicators for null-capable subfields that are not data structure subfields.
      • If both the source and target subfields are null-capable, the source subfield's null-indicator is copied to the target subfield's null-indicator.
      • If the target subfield is null-capable and the source subfield is not null-capable, the target subfield's null-indicator is set to *OFF.
      • If the source subfield is null-capable and the target subfield is not null-capable, the source subfield's null-indicator is ignored.
      • The EVAL-CORR operation sets the null-indicators for scalar and array subfields only. If a null-capable subfield is a data structure, its null-indicator will not be set by the EVAL-CORR operation; similarly, if the target data structure itself is null-capable, its null-indicator will not be set by the EVAL-CORR operation..
    • If the subfield is a data structure and a null-indicator is assigned to the data structure itself, the null-indicator is not affected by the EVAL-CORR operation.