Skip to content

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

Component Operator for Structures

This example demonstrates the component operator for structures.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    out = cl_demo_output=>new( ).
    fill_structures( ).
    out->begin_section( `struct1` ).
    display_structure1( ).
    out->next_section( `struct2` ).
    display_structure2( ).

    DATA(base) = struct2.

    out->begin_section(
      `CORRESPONDING struct2( struct1 )` ).

    struct2 = CORRESPONDING #( struct1 ).

    display_structure2( ).
    out->next_section(
      `CORRESPONDING struct2( BASE ( struct2 ) struct1 )` ).

    struct2 = CORRESPONDING #( BASE ( base ) struct1 ).

    display_structure2( ).
    out->next_section(
      `CORRESPONDING struct2( DEEP struct1 )` ).

    struct2 = CORRESPONDING #( DEEP struct1 ).

    display_structure2( ).
    out->next_section(
      `CORRESPONDING struct2( DEEP BASE ( struct2 ) struct1 )` ).

    struct2 = CORRESPONDING #( DEEP BASE ( base ) struct1 ).

    display_structure2( ).
    out->display( ).

Description

This example uses the same structures as the example for MOVE-CORRESPONDING. Here, the source structure struct1 is used as a parameter of a constructor expression with the component operator CORRESPONDING and the result is assigned to the target structure struct2. The source structure struct1 is assigned to the result with the type of struct2, both with and without the addition DEEP. If the addition BASE is used, the result is given the original value of struct2 as its start value and otherwise stays initial. The assignment is made exactly as described in the example for MOVE-CORRESPONDING with or without EXPANDING NESTED TABLES. If DEEP is used the name comparison is made for the components of the substructure col3. This is why fewer assignments are made than when omitting DEEP. The uninvolved component col4 keeps its initial value without BASE being used. If BASE is used, it keeps the set value. The result is assigned to the target structure struct2.

The result of the component operator matches the result of MOVE-CORRESPONDING only if the addition BASE is used.