ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Assignments → Assigning Structure Components → CL_ABAP_CORRESPONDING - System Class
CL_ABAP_CORRESPONDING - Assignment of Values
The method CREATE_WITH_VALUE of the system class CL_ABAP_CORRESPONDING has essentially the same function as the method CREATE. Additionally, the values of any data objects can be assigned to the components of the target structure or target table.
The factory method CREATE_WITH_VALUE is used to create a mapping object:
DATA(mapper) =
cl_abap_corresponding=>create_with_value( source
= struct|itab
destination = struct|itab
mapping = mapping_tab
discarding_duplicates = flag ).
For the parameters source
and destination
, the same applies as to the method
CREATE. An internal table of the type CL_ABAP_CORRESPONDING=>MAPPING_TABLE_VALUE,
containing the mapping rule, must be passed to the parameter mapping
. This mapping table has the same components, with the same meaning, as a mapping table of type
CL_ABAP_CORRESPONDING=>MAPPING_TABLE, with an additional column and further values for the column KIND:
- VALUE
- KIND
- CL_ABAP_CORRESPONDING=>MAPPING_VALUE (16), the value specified in VALUE is always assigned. The column SRCNAME must be initial
- CL_ABAP_CORRESPONDING=>MAPPING_DEFAULT_VALUE (32), the value specified in VALUE is only assigned if the component specified in the column SRCNAME is initial. The component name in SRCNAME must exist in the source structure.
A mapping object created with CREATE_WITH_VALUE is used like a mapping object created with CREATE with the method EXECUTE.
Other versions:
7.31 | 7.40 | 7.54
Example
The component b2
is given the value xxx and
the component b3
is given the value yyy. The
components b1
and b4
are given the values of the associated components a1
and a4
of the source structure.
DATA:
BEGIN OF struct1,
a1 TYPE string VALUE 'a1',
a2 TYPE string VALUE 'a2',
a3 TYPE string VALUE ' ',
a4 TYPE string VALUE 'a4',
END OF struct1,
BEGIN OF struct2,
b1 TYPE string VALUE 'b1',
b2 TYPE string VALUE 'b2',
b3 TYPE string VALUE 'b3',
b4 TYPE string VALUE 'b4',
END OF struct2.
DATA(mapper) =
cl_abap_corresponding=>create_with_value(
source = struct1
destination = struct2
mapping = VALUE
cl_abap_corresponding=>mapping_table_value(
( level = 0 kind = 1 srcname = 'a1' dstname = 'b1' )
( level = 0 kind = 16 dstname = 'b2'
value = REF #( `xxx` ) )
( level = 0 kind = 32 srcname = 'a3' dstname = 'b3'
value = REF #( `yyy` ) )
( level = 0 kind = 32 srcname = 'a4' dstname = 'b4'
value = REF #( `zzz` ) )
) ).
mapper->execute( EXPORTING source = struct1
CHANGING destination = struct2 ).
cl_demo_output=>display( struct2 ).