Skip to content

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

Component Operator, Components of Two Arguments

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( `itab1`
      )->write( itab1 ).

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


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

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

    itab3 = CORRESPONDING #(
              itab1 FROM itab2
                    USING KEY mkey b1 = a1 b2 = a2 ) ##operator.
    out->next_section(
      `itab3 = CORRESPONDING #( itab1 FROM itab2 USING ... )`
      )->write( itab3 ).

    out->display( ).

Description

This example joins two internal tables itab1 and itab2 in a constructor expression with the component operator CORRESPONDING, which uses the components of two arguments.

  • The first assignment specifies the conditionb1 = a1 b2 = a2 without a mapping rule after USING. In itab2, one row is found for the first and third row of itab1 and its identically named components are assigned to the corresponding row of itab1. b1 and b2 from itab2 and a1 and a2 from itab1 are ignored here. The only identically named component is c1. All other components keep their preceding value from itab1. 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 itab1 are modified.
  • Finally, the third assignment demonstrates the assignment of the expression to an internal table itab3 that does not have the type of itab1 but is compatible with it. The full result of the expression is assigned to itab3. The pragma ##operator hides the syntax check warning stating that a temporary copy of itab1 needs to be created.