ABAP - Keyword Documentation →  ABAP - Programming Language →  Processing Internal Data →  Assignments →  Assigning Structure Components →  CORRESPONDING, Component Operator → 
Mail Feedback

CORRESPONDING, Basic Form

Syntax

... { CORRESPONDING {dtype|#}( [EXACT] [DEEP]
                               struct|{itab [ duplicates]} ) }
  | { CORRESPONDING {dtype|#}( [DEEP]
                               [[APPENDING] BASE ( base )]
                               struct|{itab [ duplicates]} ) }
  | { CORRESPONDING {dtype|#}( [[APPENDING] BASE ( base )]
                               struct|{itab [ duplicates]}
                               mapping ) } ...


Additions:

1. ... EXACT ...

2. ... DEEP ...

3. ... BASE ( base ) ...

4. ... APPENDING ( base )

5. ... DEEP APPENDING ( base )

Effect

This variant of the component operator CORRESPONDING constructs a result with the target type specified using dtype or # from the components of a parameter struct or itab. struct and itab are general expression positions.

Hints

Example

Assignment of four identically named components of standard table spfli_tab to a temporarily sorted table of type flights in an operand position.

TYPES:
  BEGIN OF flight,
    carrid   TYPE spfli-carrid,
    connid   TYPE spfli-connid,
    cityfrom TYPE spfli-cityfrom,
    cityto   TYPE spfli-cityto,
  END OF flight.
TYPES
  flights TYPE SORTED TABLE OF flight WITH UNIQUE KEY carrid connid.

SELECT *
       FROM spfli
       INTO TABLE @FINAL(spfli_tab).

cl_demo_output=>display( CORRESPONDING flights( spfli_tab ) ).

Addition 1  

... EXACT ...

Effect

If the addition EXACT is specified for a structure struct, the assignment is made as with the addition EXACT of the statement MOVE-CORRESPONDING for structures. If the addition EXACT is specified for an internal table itab, the assignment is made in accordance with the rules outlined for the statement MOVE-CORRESPONDING for internal tables.

Example

Assignment of results of the component operator without and with addition EXACT to existing structures of the same content. The example with EXACT demonstrates that, if an exception is raised, all components are assigned up to the component that raised the exception. This component, and all following components, are not assigned.

DATA:
  BEGIN OF src,
    a TYPE string VALUE `AAA`,
    b TYPE string VALUE `BBB`,
    c TYPE string VALUE `CCC`,
  END OF src,
  BEGIN OF target1,
    a TYPE string,
    b TYPE c LENGTH 1,
    c TYPE string,
    d TYPE i,
  END OF target1.
DATA(target2) = target1.
target1 = CORRESPONDING #( src ).

TRY.
    target2 = CORRESPONDING #( EXACT src ).
  CATCH cx_root INTO FINAL(error).
ENDTRY.

cl_demo_output=>new( )->write( target1 )->display( target2 ).

Addition 2  

... DEEP ...

Effect

If the addition DEEP is specified, the assignment is made as with the addition EXPANDING NESTED TABLES of the statement MOVE-CORRESPONDING. A mapping rule mapping can be used to override the matching name assignment rule of MOVE-CORRESPONDING. If a mapping rule is specified, the addition DEEP is set implicitly and cannot be specified explicitly.

Hint

If the additions EXACT and DEEP are specified, the order of the additions is irrelevant, i. e. both ... EXACT DEEP ... and ... DEEP EXACT ... are possible. Furthermore, the only syntax option using both DEEP and EXACT with more additions is DISCARDING DUPLICATES.

Example

Assignment of results of the component operator with the additions DEEP and EXACT DEEP to existing deep structures of the same content.

DATA:
  BEGIN OF struc1,
    a TYPE string,
    b TYPE string,
    c TYPE i,
  END OF struc1,
  BEGIN OF struc2,
    a TYPE string,
    b TYPE c LENGTH 1,
    c TYPE i,
  END OF struc2,
  BEGIN OF str_deep1,
    comp TYPE string VALUE `ZZZ`,
    itab LIKE TABLE OF struc1 WITH EMPTY KEY,
  END OF str_deep1,
  BEGIN OF str_deep2,
    comp TYPE string,
    itab LIKE TABLE OF struc2 WITH EMPTY KEY,
  END OF str_deep2.

str_deep1-itab = VALUE #( ( a = `AAA` b = `BBB` c = 111  ) ).
DATA(str_deep3) = str_deep2.

str_deep2 = CORRESPONDING #( DEEP str_deep1 ).

TRY.
    str_deep3 = CORRESPONDING #( EXACT DEEP str_deep1 ).
  CATCH cx_root INTO FINAL(error).
ENDTRY.

cl_demo_output=>new( )->write( str_deep2 )->display( str_deep3 ).

Addition 3  

... BASE ( base ) ...

Effect

The addition BASE can be used to specify a start value base for the created structure or internal table. base is a functional operand position in which a database convertible to the target type can be specified.

If the addition BASE is specified, the value of base is assigned to the target structure or target table in accordance with the general assignment rules before the remainder of the expression is evaluated. Here, the addition duplicates after itab can be used to affect the behavior with respect to duplicate lines occurring in a target table.

Hints

Example

Assignment of results of the component operator without and with addition BASE to existing structures of the same content. The value of the component that does not exist in the source structure is only preserved if BASE is used.

DATA:
  BEGIN OF src,
    a TYPE i VALUE 1,
    b TYPE i VALUE 2,
  END OF src,
  BEGIN OF target1,
    b TYPE i VALUE 11,
    c TYPE i VALUE 12,
  END OF target1.
DATA(target2) = target1.

target1 = CORRESPONDING #( src ).
target2 = CORRESPONDING #( BASE ( target2 ) src ).

cl_demo_output=>new( )->write( target1 )->display( target2 ).

Addition 4  

... APPENDING ( base ) ...

Effect

This addition affects two identically named deep components that are both internal tables. It ensures that the nested target tables are not deleted. Furthermore, it appends the lines of the nested source tables. The value assignment applied to the added lines is performed in the same way as using the CORRESPONDING operator without addition.

Note: The entire table bodies of the nested source tables are assigned in accordance with the conversion rules for internal tables.

Hint

The addition APPENDING appends the lines of a nested table and keeps the original lines. The explicit specification of the addition BASE is possible here but not necessary. That means, the following syntax has the same effect:

struc2 = CORRESPONDING #( APPENDING ( struc2 ) struc1 ).
struc2 = CORRESPONDING #( APPENDING BASE ( struc2 ) struc1 ).

Example

The following source code section taken from CL_DEMO_CRRSPNDNG_VARIANTS_ST demonstrates the variant with deep structures containing internal tables as components.

deep_struc2 = CORRESPONDING #( APPENDING ( deep_struc2 ) deep_struc1 ).

Addition 5  

... DEEP APPENDING ( base ) ...

Effect

This combination affects two identically named components that are both internal tables. It ensures that the nested target tables are not deleted. Furthermore, it appends the lines of the nested source tables. The value assignment applied to the added lines is performed in the same way as using the CORRESPONDING operator with the addition DEEP. That is, the value assignment is only carried out for identically named components in the nested table.

Hint

The addition APPENDING appends the lines of a nested table and keeps the original lines. The explicit specification of the addition BASE is possible here but not necessary. That means, the following syntax has the same effect:

struc2 = CORRESPONDING #( DEEP APPENDING ( struc2 ) struc1 ).
struc2 = CORRESPONDING #( DEEP APPENDING BASE ( struc2 ) struc1 ).

Example

The following source code section taken from CL_DEMO_CRRSPNDNG_VARIANTS_ST demonstrates the variant with deep structures containing internal tables as components.

deep_struc2 = CORRESPONDING #( DEEP APPENDING ( deep_struc2 ) deep_struc1 ).

Executable Examples