Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Assignments →  Assigning Structure Components →  CL_ABAP_CORRESPONDING - System Class 

CL_ABAP_CORRESPONDING - Lookup Table

The methods CREATE_USING and EXECUTE_USING of the system class CL_ABAP_CORRESPONDING can be used to assign components between internal tables with a dynamically specified mapping rule. The source table is used as a lookup table.

The factory method CREATE_USING is used to create a mapping object:

DATA(mapper) = cl_abap_corresponding=>create_using( destination = itab
                                                    using       = lookup_tab
                                                    mapping     = mapping_tab ).

Internal tables itab and lookup_table, with the table types to which the assignment applies, must be passed to the parameters destination and using. An internal table of the type CL_ABAP_CORRESPONDING=>MAPPING_TABLE, containing the mapping rule, must be passed to the parameter mapping. The mapping table has the same components as the methods for simple assignments with the following special semantics:

  • KIND
Mapping type. The additional possible values are:
  • CL_ABAP_CORRESPONDING=>USING_KEY (4), the table key of the lookup table used for the evaluation is specified in the component SRCNAME in this row. The table must contain a row like this.
  • CL_ABAP_CORRESPONDING=>MAPPING_USING_COMPONENT (5), the name of a column of the lookup table in SRCNAME is associated with the name of a column of the target table in DSTNAME in a row like this. All key fields of the table key used must be covered by a row like this.
The mapping types for simple assignments can also be used and have the same semantics as described here.

The method EXECUTE_USING of a mapping object can be used to perform any number of assignments between tables lookup_src and dst whose data type matches the source type or target type lookup_tab or itab specified when the object was created:

mapper->execute_using( EXPORTING using       = lookup_src
                       CHANGING  destination = dst ).

For each row in dst, a row is found in the lookup table lookup_src that matches this row in accordance with the relationship defined using the mapping type CL_ABAP_CORRESPONDING=>MAPPING_USING_COMPONENT in the mapping table. If the key is not unique, the first row found is used. If no row like this is found, the row from dst remains unchanged. If a row like this is found in lookup_src, it is assigned to the row from dst in accordance with the rules of MOVE-CORRESPONDING for structures using the addition EXPANDING NESTED TABLES, with the following exception. The components used for the search are not assigned by default. The rows in the mapping table with mapping types for simple assignments can be used to override the default assignment of identically named components and the default exclusion of the components used for the search. It is not possible to specify the same table for dst and lookup_src; if specified, the runtime error CORRESPONDING_SELF occurs.

Other versions: 7.31 | 7.40 | 7.54


Notes

  • The methods CREATE_USING and EXECUTE_USING of the system class CL_ABAP_CORRESPONDING produce an assignment similar to the statement
dst = CORRESPONDING #( dst FROM lookup_tab KEY key_name ... ).
Here, however. the columns used to synchronize the target table and lookup table, plus the mapping rule are specified dynamically as the content of a special internal table.

  • In the mapping table, the columns of the target table dst are part of the column DSTNAME, regardless of the mapping type, and the columns of the lookup table are part of the column SRCNAME. In the CORRESPONDING operator, however, the arrangement of the operands after USING is different from the arrangement after MAPPING.

Example

The example displays the implementation of an example for component operator CORRESPONDING with lookup table to class CL_ABAP_CORRESPONDING.

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 ). 

cl_demo_output=>display( itab1 ).

Executable Example

CL_ABAP_CORRESPONDING with Lookup Table