I'm on ABAP 7.4 SP13.
I would like to use "Option 2" in the code below, but how can I do this deep mapping? The goal here is to have a clean, simple, easy-to-read mapping, avoiding the loop.
TYPES:
BEGIN OF ty_s_audit,
CreatedBy TYPE ernam,
LastChangedBy TYPE aenam,
END OF ty_s_audit,
BEGIN OF ty_s_equipment,
EquipmentId TYPE equi-equnr,
Audit TYPE ty_s_audit BOXED,
END OF ty_s_equipment,
ty_t_equipment TYPE STANDARD TABLE OF ty_s_equipment WITH KEY PRIMARY_KEY COMPONENTS EquipmentId.
DATA: lt_equipments TYPE ty_t_equipment.
SELECT equnr, ernam, aenam FROM equi INTO TABLE @DATA(lt_equi).
"Option 1:
LOOP AT lt_equi ASSIGNING FIELD-SYMBOL(<ls_equi>).
APPEND INITIAL LINE TO lt_equipments ASSIGNING FIELD-SYMBOL(<ls_equipment>).
<ls_equipment> = CORRESPONDING #( <ls_equi> MAPPING EquipmentId = EQUNR ).
<ls_equipment>-Audit = CORRESPONDING #( <ls_equi> MAPPING CreatedBy = ERNAM
LastChangedBy = AENAM ).
ENDLOOP.
"Option 2:
lt_equipments = CORRESPONDING #( lt_equi MAPPING EquipmentId = EQUNR
“Audit-CreatedBy = ERNAM
“Audit-LastChangedBy = AENAM ).
Well, what about the following solution?
lt_equipments = VALUE #( FOR i IN lt_equi
(
equipmentid = i-equnr
audit-createdby = i-ernam
audit-lastchangedby = i-aenam
)
).
Or if you really want to use CORRESPONDING MAPPING somewhere then for example.
lt_equipments = VALUE #( FOR i IN lt_equi
(
equipmentid = i-equnr
audit = CORRESPONDING #( i MAPPING createdby = ernam lastchangedby = aenam )
)
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With