码迷,mamicode.com
首页 > 其他好文 > 详细

ABAP中Collect的用法

时间:2017-08-06 23:13:13      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:效果   test   相加   技术   attribute   begin   pen   log   插入   

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的用法

标签:效果   test   相加   技术   attribute   begin   pen   log   插入   

原文地址:http://www.cnblogs.com/HARU/p/7296075.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!