Skip to content

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

CL_ABAP_CORRESPONDING for Internal Tables

This example demonstrates the system class CL_ABAP_CORRESPONDING for internal tables.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    TYPES: BEGIN OF line1,
             col1 TYPE i,
             col2 TYPE i,
           END OF line1,
           BEGIN OF line2,
             col2 TYPE i,
             col3 TYPE i,
           END OF line2.

    DATA: itab1 TYPE TABLE OF line1 WITH EMPTY KEY,
          itab2 TYPE TABLE OF line2 WITH EMPTY KEY.

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

    itab1 = VALUE #(
      ( col1 = 11 col2 = 12 )
      ( col1 = 21 col2 = 22 ) ).

    itab2 = VALUE #(
      ( col2 = 212 col3 = 312 )
      ( col2 = 222 col3 = 322 ) ).

   cl_abap_corresponding=>create(
      source            = itab1
      destination       = itab2
      mapping           = VALUE cl_abap_corresponding=>mapping_table(  )
      )->execute( EXPORTING source      = itab1
                  CHANGING  destination = itab2 ).
    out->write( itab2 ).

    cl_abap_corresponding=>create(
      source            = itab1
      destination       = itab2
      mapping           = VALUE cl_abap_corresponding=>mapping_table(
       ( level = 0 kind = 1 srcname = 'col1' dstname = 'col2' )
       ( level = 0 kind = 1 srcname = 'col2' dstname = 'col3' ) )
      )->execute( EXPORTING source      = itab1
                  CHANGING  destination = itab2 ).
    out->write( itab2 ).

    out->display( ).

Description

The components of the internal table itab1 are assigned to the internal table itab2 using the system class CL_ABAP_CORRESPONDING.

  • The mapping table is empty in the first assignment. The assignment is made as in MOVE-CORRESPONDING using matching names and the column col3 of the target table is not filled.
  • In the second assignment, a mapping table is passed that assigns all columns of the source table to a column in the target table regardless of their names.