Ansicht
Dokumentation

ABENCL_ABAP_CORRESPONDING_1 - CL ABAP CORRESPONDING 1

ABENCL_ABAP_CORRESPONDING_1 - CL ABAP CORRESPONDING 1

Fill RESBD Structure from EBP Component Structure   TXBHW - Original Tax Base Amount in Local Currency  
This documentation is copyright by SAP AG.
SAP E-Book

CL_ABAP_CORRESPONDING, Simple Assignment

The methods CREATE and EXECUTE of the system class CL_ABAP_CORRESPONDING can be used to assign components between structures or between internal tables with a dynamically specified mapping rule.

The factory method CREATE is used to create a mapping object:

DATA(mapper) = cl_abap_corresponding=>create( source  = struct$|itab
                                              destination           = struct$|itab
                                              mapping               = mapping_tab
                                              discarding_duplicates = flag ).

Structures struct or internal tables itab of data types for which the assignment is to be executed must be passed to the parameters source and destination. An internal table of the type CL_ABAP_CORRESPONDING=>MAPPING_TABLE, which contains the mapping rule, must be passed to the parameter mapping. If an initial mapping table is passed, only the identically named components are assigned. The mapping table has the following components:

  • LEVEL
Level of the components in the structure or line structure. The value 0 represents the top level.
  • KIND
Mapping type. The possible values are:
  • CL_ABAP_CORRESPONDING=>MAPPING_COMPONENT (1) The components specified in this line are mapped to each other.

  • CL_ABAP_CORRESPONDING=>MAPPING_EXCEPT_COMPONENT (2) The component of the source structure specified in this line is excluded from the mapping of identically named components.

  • CL_ABAP_CORRESPONDING=>MAPPING_EXCEPT_ALL (3) All components of the current source structure are excluded from the mapping of identically name components.

  • CL_ABAP_CORRESPONDING=>MAPPING_DISCARDING_DUPLICATES (9) In a source table, duplicate rows are ignored as when using DISCARDING DUPLICATES in a mapping rule of the component operator. The target table must have a unique table key.

  • SRCNAME
Component of the source structure.
  • DSTNAME
Component of the target structure.

The lines of the internal table must be constructed so that they result in a mapping rule in the correct order. Components of the source structure for which no mapping is defined and that were not excluded are assigned identically named components of the target structure.

The method EXECUTE of a mapping object can be used to perform any number of assignments between structures or internal tables src and dst whose data type matches the source type or target type specified when the object was created:

mapper->execute( EXPORTING source      = src
                 CHANGING  destination = dst ).

The assignment is performed component by component

  • between the components specified in the mapping rule
  • between the remaining identically named components at the same level if they were not excluded in the mapping rule.

In assignments between structures, components of the target structure to which no components of the source structure are assigned keep their previous value, like the statement MOVE-CORRESPONDING and like the operator CORRESPONDING with the addition BASE. Nested internal tables are always resolved, as if the addition EXPANDING NESTED TABLES is specified in MOVE-CORRESPONDING or the addition DEEP for the operator CORRESPONDING. In assignments between internal tables, the target table is always initialized first. There is no equivalent for the addition KEEPING TARGET LINES in MOVE-CORRESPONDING or BASE in CORRESPONDING.

If the value "X" was passed to the parameter DISCARDING_DUPLICATES of the method CREATE, duplicate rows are handled in tabular component assignments in the same way as when using the addition DISCARDING DUPLICATES in the basic form of the component operator. Here, the target table must have a unique table key.

The source and the target may be the same. However, it should be noted that, unlike in the operator CORRESPONDING for reflexive assignments. the target object is used directly like in the statement MOVE-CORRESPONDING and no temporary interim result is created.

The passing of incorrect parameters to the methods of the class CL_ABAP_CORRESPONDING raises exceptions of the class CX_CORR_DYN_ERROR.

Notes

  • The methods CREATE and EXECUTE of the system class CL_ABAP_CORRESPONDING implement an assignment similar to the statement
dst = CORRESPONDING  #( BASE ( dst ) struct$|itab MAPPING ... EXCEPT ... ).
Here, the mapping rule is specified dynamically, however, as the content of a special internal table.
  • The same restrictions apply as to the operator CORRESPONDING. Components can only be mapped to each other if they are on the same level. Components of a substructure cannot be assigned to the components at higher levels and vice versa.
  • The class CL_ABAP_CORRESPONDING always resolves tabular components, which corresponds to the behavior of the operator CORRESPONDING if a mapping rule is specified. In this case, the addition DEEP is also set implicitly.
  • To achieve the same results for standalone components in assignments between structures as in the operator CORRESPONDING without the addition BASE, an initial structure can be assigned to the parameter destination.
  • In reflexive assignments between components of the same object, as in MOVE-CORRESPONDING, it should be noted that the processing order is not defined and that a call of the method EXECUTE cannot be used to swap the content of two components. See the executable example Reflexive Component Assignments.

Example

Use of the class CL_ABAP_CORRESPONDING for assignments of components to a simple structure. The mapping rule specifies that the components a3 are assigned to b1 and a1 to b3. The component a2 is ignored since there are no identically named components in the target structure and b2 keeps its value. a4 and a5 in the target structure also keep their values, even though the source structure contains identically named components, since the value of CL_ABAP_CORRESPONDING=>MAPPING_EXCEPT_ALL is specified for the mapping type for all non-specified components. The executable example for simple structures enables interactive input of the component names that are mapped to each other.






BAL_S_LOG - Application Log: Log header data   CPI1466 during Backup  
This documentation is copyright by SAP AG.

Length: 10775 Date: 20240418 Time: 202853     sap01-206 ( 147 ms )