Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Assignments →  Assigning Structure Components →  Assigning Components: Examples 

CL_ABAP_CORRESPONDING with Lookup Table

This example demonstrates the system class CL_ABAP_CORRESPONDING with a lookup table

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA(out) = cl_demo_output=>new( ).

    out->begin_section( `itab`
      )->write( itab ).

    out->next_section(
      `lookup_tab`
      )->write( lookup_tab ).

    DATA(mapping_tab) = VALUE cl_abap_corresponding=>mapping_table(
      ( level = 0 kind = 4 srcname = 'PRIMARY_KEY' )
      ( level = 0 kind = 5 srcname = 'B1' dstname = 'A1' )
      ( level = 0 kind = 5 srcname = 'B2' dstname = 'A2' ) ).
    cl_abap_corresponding=>create_using(
      destination       = itab
      using             = lookup_tab
      mapping           = mapping_tab
      )->execute_using( EXPORTING using       = lookup_tab
                        CHANGING  destination = itab ).
    out->next_section(
      `CL_ABAP_CORRESPONDING=>EXECUTE_USING without mapping`
      )->write( itab ).

    mapping_tab = VALUE cl_abap_corresponding=>mapping_table(
       ( level = 0 kind = 4 srcname = 'PRIMARY_KEY' )
       ( level = 0 kind = 5 srcname = 'B1' dstname = 'A1' )
       ( level = 0 kind = 5 srcname = 'B2' dstname = 'A2' )
       ( level = 0 kind = 1 srcname = 'A1' dstname = 'A1' )
       ( level = 0 kind = 1 srcname = 'A2' dstname = 'A2' )
       ( level = 0 kind = 1 srcname = 'B1' dstname = 'B1' )
       ( level = 0 kind = 1 srcname = 'B2' dstname = 'B2' )
       ( level = 0 kind = 1 srcname = 'D2' dstname = 'C2' )  ).
    cl_abap_corresponding=>create_using(
      destination       = itab
      using             = lookup_tab
      mapping           = mapping_tab
      )->execute_using( EXPORTING using       = lookup_tab
                        CHANGING  destination = itab ).
    out->next_section(
    `CL_ABAP_CORRESPONDING=>EXECUTE_USING with mapping`
      )->write( itab ).

    out->display( ).

Description

This example shows how the first two uses of the component operator CORRESPONDING in the executable example Component Operator, Lookup Table in can be transformed to method calls for the class CL_ABAP_CORRESPONDING. The results are the same in both cases. The third way of using the component operator cannot be reflected here, since the method EXECUTE_USING uses a CHANGING parameter and hence the source table always matches the target table.