Ansicht
Dokumentation

ABAPMOVE-CORRESPONDING_STRUCTURE - MOVE-CORRESPONDING STRUCTURE

ABAPMOVE-CORRESPONDING_STRUCTURE - MOVE-CORRESPONDING STRUCTURE

SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up   ABAP Short Reference  
This documentation is copyright by SAP AG.
SAP E-Book

MOVE-CORRESPONDING, structure

Short Reference



MOVE-CORRESPONDING $[EXACT$] struc1 TO struc2
  $[EXPANDING NESTED TABLES$] $[KEEPING TARGET LINES$].


Additions

1. ... EXACT

2. ... EXPANDING NESTED TABLES

3. ... KEEPING TARGET LINES

4. ... EXPANDING NESTED TABLES KEEPING TARGET LINES

Effect

This variant of the statement MOVE-CORRESPONDING requires structures to be specified for struc1 and struc2. As operands of the statement MOVE-CORRESPONDING, meshes are handled like regular structures and can also be specified.

The system searches for all identically named components in struc1 and struc2 and the content of components in struc1 is assigned to the identically named components in struc2. Other components are not affected. If field symbols are used as operands, the names of the components are evaluated in accordance with the data type of the field symbols, which can be distinguished by casting the names of the actual structures.

Nested structures are fully resolved. The names of the components are compared down to the lowest common level. If the addition EXPANDING NESTED TABLES is not specified, the following statement is executed identically for each named component pair comp:

struc2-comp = struc1-comp.

Any associated conversions are performed, and the corresponding exceptions may be raised. In particular, if the components are table-like, the entire table body is assigned in accordance with the conversion rules for internal tables.

If struc1 or struc2 are empty customizing includes when the statement is executed (that is they do not contain any components), the statement is ignored. If struc1 is a structure that contains empty customizing includes as components, these are also ignored when the structure is evaluated.

Notes

  • If structures are specified for struc1 and struc2 that are known statically, the names are compared once when the program is generated by the ABAP Compiler. If untyped field symbols or formal parameters are used, the associated names comparison must be performed each time the statement is executed.
  • Field symbols that point to structures can have different names for the components than the structure itself, as specified by the CASTING addition of the statement ASSIGN. The statement MOVE-CORRESPONDING evaluates the names of the data type of the current operand. This means that components in the same structure can also be assigned to each other. Note that the order of processing and therefore the result in a component that is used both as a source and as a target is usually undefined. No temporary interim result is created, and it is not possible to exchange the content of two components of the same structure in a single statement. See the executable example Reflexive Component Assignments.
  • The compiler optimizes the MOVE-CORRESPONDING statement for structures so that sequences of components that have the same names in both structures are grouped and copied together. It is therefore recommended that the involved structures are constructed in the same way if possible.
  • MOVE-CORRESPONDING for structures ignores names that were only defined with the AS name addition of the INCLUDE statement or when structures were included in the ABAP Dictionary. Any components renamed using the addition RENAMING WITH SUFFIX of the statement INCLUDE or renamed similarly in the ABAP Dictionary are, however, not ignored.

Addition 1

... EXACT

Effect

If the addition EXACT is specified for MOVE-CORRESPONDING, the following lossless assignment is performed for each identically named component pair comp

struc2-comp = EXACT #( struc1-comp ).

and the corresponding checks are performed. 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.

Addition 2

... EXPANDING NESTED TABLES

Effect

With this addition, two identically named components, that are both internal tables, are not simply assigned. Instead, for these components, the statement MOVE-CORRESPONDING $[EXACT$] for internal tables with the addition EXPANDING NESTED TABLES and without the addition KEEPING TARGET LINES is executed.

Tabular components are resolved at every hierarchy level and identically named components are assigned line by line. The target tables are deleted before an assignment.

Note

If one of two identically named components is an internal table and the other is not, MOVE-CORRESPONDING is never possible, regardless of whether EXPANDING NESTED TABLES is used.



Addition 3

... KEEPING TARGET LINES

Effect

This addition affects two identically named components that are both internal tables. It ensures that the nested target tables in struc2 are not deleted. Furthermore, it appends the lines of the nested source tables in struc1 by executing the statement MOVE-CORRESPONDING [EXACT] for internal tables without an addition.

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

Addition 4

... EXPANDING NESTED TABLES KEEPING TARGET LINES

Effect

This addition affects two identically named components that are both internal tables. It ensures that the nested target tables in struc2 are not deleted. Furthermore, it appends the lines of the nested source tables in struc1 by executing the statement MOVE-CORRESPONDING [EXACT] EXPANDING NESTED TABLES for internal tables without an addition.

In the following example, the structure struc1 contains the components:

  • struc1-comp1
  • struc1-struci-comp1
  • struc1-struci-comp2-col1
  • struc1-struci-comp2-col2
  • struc1-itab

The structure struc2 contains the components:

  • struc2-struci-comp1
  • struc2-struci-comp2
  • struc2-struci-comp3
  • struc2-itab

Over the length of the shorter path, the components struci-comp1, struci-comp2, and itab have the same name. These are assigned from struc1 to struc2 in both MOVE-CORRESPONDING statements. In struc1, struci-comp2 is self-structured; in struc2, struci-comp2 is elementary. When struc1-struci-comp2 is assigned to struc2-struci-comp2, the source field is interpreted as an elementary field of type c in accordance with the conversion rules for structures.

The components itab are table-like and have compatible line types. The statement MOVE-CORRESPONDING without the addition EXPANDING NESTED TABLE is used to assign the table body and the content of itab in struc2 then matches the content of itab in struc1. If the addition EXPANDING NESTED TABLE is used, only the component col2 is assigned and col3 remains initial.

The components struc1-comp1 and struc2-struci-comp3 do not have any equivalents with the same name and are ignored in the assignment.

This example shows how MOVE-CORRESPONDING is applied to two structures with the same type t_str and which are cast using field symbols with different types. The statement evaluates the names of the types of the field symbols, whereby the content of components that actually have different names are assigned.

This example shows how MOVE-CORRESPONDING is applied to two structures with the same type t_str and which are cast using field symbols with different types. The statement evaluates the names of the types of the field symbols, whereby the content of components that actually have different names are assigned.






General Data in Customer Master   ABAP Short Reference  
This documentation is copyright by SAP AG.

Length: 11106 Date: 20240424 Time: 083922     sap01-206 ( 165 ms )