gpt4 book ai didi

abap - 使用 CORRESPONDING without LOOP 对平面结构进行映射

转载 作者:行者123 更新时间:2023-12-04 19:46:14 26 4
gpt4 key购买 nike

我使用的是 ABAP 7.4 SP13。

我想在下面的代码中使用“选项 2”,但是如何进行这种深度映射?这里的目标是有一个干净、简单、易于阅读的映射,避免循环。

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 ).

最佳答案

那么,下面的解决方案呢?

lt_equipments = VALUE #( FOR i IN lt_equi
(
equipmentid = i-equnr
audit-createdby = i-ernam
audit-lastchangedby = i-aenam
)
).

或者,如果您真的想在某处使用 CORRESPONDING MAPPING,那么例如。

lt_equipments = VALUE #( FOR i IN lt_equi
(
equipmentid = i-equnr
audit = CORRESPONDING #( i MAPPING createdby = ernam lastchangedby = aenam )
)
).

关于abap - 使用 CORRESPONDING without LOOP 对平面结构进行映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48525350/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com