首页 > 代码库 > ABAP中Collect的用法
ABAP中Collect的用法
vaule:collect在非数值字段相同的情况下,起到了数值字段汇总作用。
非数值字段不同的情况下,效果和append相同执行插入内表操作,当非数值字段相同的时候,则相当于modify的效果,只不过是将数值字段进行汇总相加后更新。
语法:collect W_table into I_table .
代码如下:
TYPES:BEGIN OF TY_TEST,
ID(3) TYPE C,
MENGE TYPE I,
END OF TY_TEST.
DATA:I_TEST TYPE TABLE OF TY_TEST,
W_TEST TYPE TY_TEST.
DATA:I_TEST2 TYPE TABLE OF TY_TEST.
W_TEST-ID = ‘001‘.
W_TEST-MENGE = 10.
APPEND W_TEST TO I_TEST.
W_TEST-ID = ‘001‘.
W_TEST-MENGE = 70.
APPEND W_TEST TO I_TEST.
W_TEST-ID = ‘002‘.
W_TEST-MENGE = 20.
APPEND W_TEST TO I_TEST.
W_TEST-ID = ‘002‘.
W_TEST-MENGE = 50.
APPEND W_TEST TO I_TEST.
W_TEST-ID = ‘002‘.
W_TEST-MENGE = 80.
APPEND W_TEST TO I_TEST.
W_TEST-ID = ‘003‘.
W_TEST-MENGE = 30.
APPEND W_TEST TO I_TEST.
W_TEST-ID = ‘003‘.
W_TEST-MENGE = 90.
APPEND W_TEST TO I_TEST.
LOOP AT I_TEST INTO W_TEST.
COLLECT W_TEST INTO I_TEST2."关键一步。。。"
CLEAR:W_TEST.
ENDLOOP.
WRITE:/ ‘Collect前的内容:‘ .
WRITE:/1(12) ‘编号‘ , ‘数量‘.
LOOP AT I_TEST INTO W_TEST.
WRITE:/ W_TEST-ID, ‘ ‘,W_TEST-MENGE.
CLEAR:W_TEST.
ENDLOOP.
WRITE:/ .
WRITE:/ ‘Collect后的结果:‘ .
WRITE:/1(12) ‘编号‘ , ‘数量‘.
LOOP AT I_TEST2 INTO W_TEST.
WRITE:/ W_TEST-ID , ‘ ‘,W_TEST-MENGE.
CLEAR:W_TEST.
ENDLOOP.
ABAP中Collect的用法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。