admin管理员组文章数量:1125582
Is there any way we can clear for loop structure fields in sap abap and return it back to new internal table.
LOOP AT lt_a INTO DATA(ls_a).
CLEAR: ls_a-f1, ls_a-f2.
APPEND ls_a TO lt_n.
ENDLOOP.
Can we achieve this scenario using FOR loop, Something like below?
lt_n = VALUE #( FOR <ls_a> IN LT_A ( f1 = '' f2 = '' ) ).
I need to send the complete structure <ls_a>
with clear fields f1
and f2
to lt_n
without mapping each field for <ls_a>
.
Is there any way we can clear for loop structure fields in sap abap and return it back to new internal table.
LOOP AT lt_a INTO DATA(ls_a).
CLEAR: ls_a-f1, ls_a-f2.
APPEND ls_a TO lt_n.
ENDLOOP.
Can we achieve this scenario using FOR loop, Something like below?
lt_n = VALUE #( FOR <ls_a> IN LT_A ( f1 = '' f2 = '' ) ).
I need to send the complete structure <ls_a>
with clear fields f1
and f2
to lt_n
without mapping each field for <ls_a>
.
2 Answers
Reset to default 1I think this will do it, if the field names are the same:
lt_n = VALUE #( FOR <ls_a> IN lt_a
( CORRESPONDING #( <ls_a>
MAPPING f1 = DEFAULT VALUE #( )
f2 = DEFAULT VALUE #( ) ) ).
You may use BASE
followed by the structured variable to set its initial value and followed by one or more field assignments to make the base vary. Documentation of BASE
for structures: VALUE, Structures.
Demonstration:
TYPES: begin of ts_a,
f0 TYPE string,
f1 TYPE string,
end of ts_a.
TYPES tt_a TYPE STANDARD TABLE OF ts_a WITH EMPTY KEY.
DATA(lt_a) = VALUE tt_a( ( f0 = 'F0' f1 = 'F1' ) ).
DATA(lt_n) = VALUE tt_a( FOR <ls_a> IN lt_a ( VALUE #( BASE <ls_a> f1 = '' ) ) ).
" Expected result:
ASSERT lt_n = VALUE tt_a( ( f0 = 'F0' f1 = '' ) ).
本文标签:
版权声明:本文标题:Clear Structure field in FOR loop in ABAP - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736664186a1946572.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论