Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
horst_keller
Product and Topic Expert
Product and Topic Expert
42,817

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.

  • Before ABAP 7.40, these were mainly MOVE-CORRESPONDING for the components of structures, the CORRESPONDING addition to Open SQL's SELECT, and some obsolete calculation statements.

  • With ABAP 7.40 MOVE-CORRESPONDING was enabled to handle structured internal tables and a new constructor operator CORRESPONDING was introduced that allows an explicit mapping of structure components with different names.

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.

25 Comments
Labels in this area