SAP REFLEXIVE CORRESPONDING ABEXA



Get Example source ABAP code based on a different SAP table
  



Reflexive Component Assignments
This example demonstrates assignments between components of a structure.

ABAP_SOURCE_CODE
DEMO CL_DEMO_CRRSPNDNG_REFLEXIVE

ABAP_DESCRIPTION
The example summarizes different ways of making assignments of components in the same structure:
In the case of the statement, MOVE-CORRESPONDING this can be done using castings with differently typed field symbols:
There is no overlapping of source components and target components between the type t_str1 of the structure str1 and the type t_str2 of the field symbol fs2. In assignments of the structure to the field symbol that points to the structure, the content of the columns a1 and a2 is copied to the columns a3 and a4 because these columns have the names a1 and a2 in the field symbol. In assignments from the field symbol to the structure, however, the content of the columns a3 and a4 is copied to the columns a1 and a2.
Identically named components overlap between the type t_str1 of the structure str1 and the type t_str3 of the field symbol fs3. In assignments of the structure to the field symbol that points to the structure, the components are evaluated in an undefined order and the previously assigned current content of the components is used. Assignments from the field symbol to the structure produce yet another result. If performed at all, reflexive assignments between the components of a structure using MOVE-CORRESPONDING should be free of overlaps.
In the case of the basic form of the constructor operator CORRESPONDING, a temporary copy of the structure is created as a target object and assignment is made to this copy. The two mapping rules reflect the expectations of the two preceding MOVE-CORRESPONDING statements and produce the expected result.
The method EXECUTE of the system class CL_ABAP_CORRESPONDING is called using the same mapping rules as the two preceding constructor operators CORRESPONDING. No temporary copy of the structure is created as a target object, which means that the result is again the same as in the examples for MOVE-CORRESPONDING. In the case of dynamic mappings using CL_ABAP_CORRESPONDING, the source and target component should also be free of overlap.