In ABAP, as a rule, the name is not always the game (see an entertaining recent discussion about that).
But as you all know there is a prominent exception to that rule: All the syntax forms involving CORRESPONDING for assigning structure components that (by chance) have the same name.
What was still missing? A dynamic mapping capability! And this was introduced with ABAP 7.50.
The new system class CL_ABAP_CORRESPONDING allows you to assign components of structures or internal tables with dynamically specified mapping rules.
The mapping rules are created in a mapping table that is passed to a mapping object, e.g. as follows:
DATA(mapper) =
cl_abap_corresponding=>create(
source = struct1
destination = struct2
mapping = VALUE cl_abap_corresponding=>mapping_table(
( level = 0
kind = cl_abap_corresponding=>mapping_component
srcname = '...'
dstname = '...' )
( level = 0
kind = cl_abap_corresponding=>mapping_component
srcname = '...'
dstname = '...' )
( level = 0
kind = cl_abap_corresponding=>mapping_component
srcname = '...'
dstname = '...' ) ) ).
This is a simple example, where all structure components are on top level (0) and where all components are to be mapped (kind = cl_abap_coresponding=>mapping_component). More complicated forms involve nested structures and exclusions. With srcname and dstname the component names can be specified dynamically. The table setup is similar to the mapping-clause of the CORRESPONDING operator.
After creating the mapping object, all you have to do is to execute the assignment as follows:
mapper->execute( EXPORTING source = struct1
CHANGING destination = struct2 ).
You can do that again and again for all structures or internal tables that have the same types as those used for creating the mapping object.
Not much more to say about that. For details and more examples see CL_ABAP_CORRESPONDING - System Class.
Outlook
Up to now, only the basic form of the CORRESPONDING operator is mirrored in CL_ABAP_CORRESPONDING. But a variant for using a lookup table is already in the queue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
3 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |