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
With release 7.50 we introduced the system class CL_ABAP_CORRESPONDING that allows you to do dynamically what you can do with the CORRESPONDING operator statically.

There were two gaps in CL_ABAP_CORRESPONDING that are closed now.

 

Usage of a Lookup Table


The CORRESPONDING operator has two variants, one base form and one with a lookup table. The latter constructs an internal table by looking up another table and using the lines found there as sources of the corresponding assignment:
TYPES: 
BEGIN OF line,
value TYPE i,
comment TYPE string,
END OF line,
itab1 type STANDARD TABLE OF line WITH EMPTY KEY,
itab2 TYPE HASHED TABLE OF line WITH UNIQUE KEY value.

DATA(itab1) = VALUE itab1( for i = 1 UNTIL i >= 10 ( value = i ) ).
DATA(itab2) = VALUE itab2( ( value = 2 comment = `...` )
( value = 3 comment = `...` )
( value = 5 comment = `...` )
( value = 8 comment = `...` ) ).

itab1 = CORRESPONDING itab1( itab1 FROM itab2 USING value = value ).

In this simple example, the lines of  itab1 that are available in itab2 are taken over to itab1.

In release 7.50, this opportunity was missing for CL_ABAP_CORRESPONDING  but is made available in release 7.51:
TYPES: 
BEGIN OF line,
value TYPE i,
comment TYPE string,
END OF line,
itab1 TYPE STANDARD TABLE OF line WITH EMPTY KEY,
itab2 TYPE HASHED TABLE OF line WITH UNIQUE KEY value.

DATA(itab1) = VALUE itab1( FOR i = 1 UNTIL i >= 10 ( value = i ) ).
DATA(itab2) = VALUE itab2( ( value = 2 comment = `...` )
( value = 3 comment = `...` )
( value = 5 comment = `...` )
( value = 8 comment = `...` ) ).

DATA(mapping_tab) = VALUE cl_abap_corresponding=>mapping_table(
( level = 0 kind = 4 srcname = 'PRIMARY_KEY' )
( level = 0 kind = 5 srcname = 'VALUE' dstname = 'VALUE' ) ).

cl_abap_corresponding=>create_using(
destination = itab1
using = itab2
mapping = mapping_tab
)->execute_using( EXPORTING using = itab2
CHANGING destination = itab1 ).

This example does the same using CL_ABAP_CORRESPONDING as the example for CORRESPONDING above. In real life you use variables instead of literals of course.

For more information see CL_ABAP_CORRESPONDING - Lookup Table.

 

Reflexive Assignments


In release 7.50 source and target must not be the same when using CL_ABAP_CORRESPONDING otherwise the runtime error CORRESPONDING_SELF can occur.

See the respective example for release 7.50,  where the reflexive assignments with CL_ABAP_CORRESPONDING are prepared but not possible yet.

Now see the same example for release 7.51. Reflexive assignments with CL_ABAP_CORRESPONDING are possible now.
    cl_abap_corresponding=>create(
source = str1
destination = str1
mapping = VALUE cl_abap_corresponding=>mapping_table(
( level = 0 kind = 1 srcname = 'a4' dstname = 'a1' )
( level = 0 kind = 1 srcname = 'a3' dstname = 'a2' )
( level = 0 kind = 1 srcname = 'a1' dstname = 'a3' )
( level = 0 kind = 1 srcname = 'a2' dstname = 'a4' ) )
)->execute( EXPORTING source = str1
CHANGING destination = str1 ).
7 Comments
Labels in this area