Skip to content

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

Component operator, lookup table

This example demonstrates the component operator with FROM ... USING.

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

    itab = CORRESPONDING #(
              itab FROM lookup_tab
                   USING KEY mkey b1 = a1 b2 = a2 ).
    out->next_section(
      `itab = CORRESPONDING #( itab FROM lookup_tab USING ... )`
      )->write( itab ).

    itab = CORRESPONDING #(
              itab FROM lookup_tab
                   USING KEY mkey b1 = a1 b2 = a2
                   MAPPING a1 = a1 a2 = a2 b1 = b1 b2 = b2 c2 = d2 ).
    out->next_section(
    `itab = CORRESPONDING #( itab FROM lookup_tab ` &&
                                `USING ... MAPPING ... )`
      )->write( itab ).

    jtab = CORRESPONDING #(
             itab FROM lookup_tab
                  USING KEY mkey b1 = a1 b2 = a2 ) ##operator.
    out->next_section(
      `jtab = CORRESPONDING #( itab FROM lookup_tab USING ... )`
      )->write( jtab ).

    out->display( ).

Description

This example joins two internal tables itab and itab2 in a constructor expression with the component operator CORRESPONDING, which uses the variant with lookup table.

  • The first assignment specifies the conditionb1 = a1 b2 = a2 without a mapping rule after USING. In the lookup_tab, one row is found for the first and third row of itab and its identically named components are assigned to the corresponding row of itab, where b1 and b2 from lookup_tab and a1 and a2 from itab are ignored here. The only identically named component is c1. All other components keep their preceding value from itab. The second row is taken unchanged from itab1.
  • In the second assignment, the default handling by specifying a mapping rule a1 = a1 a2 = a2 b1 = b1 b2 = b2 c2 = d2 is overridden by specifying a mapping relationship for all components ignored until now. Accordingly, the content of all components in the first and third row of itab are modified.
  • Finally, the third assignment still demonstrates the assignment of the expression to an internal table jtab that does not have the type of itab but is compatible with it. The full result of the expression is assigned to jtab. The pragma ##operator hides the syntax check warning stating that a temporary copy of itab needs to be created.