[ABAP]collect

别来无恙 提交于 2019-12-02 14:38:33
REPORT ZCALCUATOR.

TYPES:BEGIN OF TY_TEST,
ID(3) TYPE C,
  DS(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.
W_TEST-DS = '123'.
APPEND W_TEST TO I_TEST.

W_TEST-ID = '001'.
W_TEST-MENGE = 70.
W_TEST-DS = '123'.
APPEND W_TEST TO I_TEST.

W_TEST-ID = '002'.
W_TEST-MENGE = 20.
W_TEST-DS = '1'.
APPEND W_TEST TO I_TEST.

W_TEST-ID = '002'.
W_TEST-MENGE = 50.
W_TEST-DS = '1'.
APPEND W_TEST TO I_TEST.

W_TEST-ID = '002'.
W_TEST-MENGE = 80.
W_TEST-DS = '3'.
APPEND W_TEST TO I_TEST.

W_TEST-ID = '003'.
W_TEST-MENGE = 30.
W_TEST-DS = '3'.
APPEND W_TEST TO I_TEST.

W_TEST-ID = '003'.
W_TEST-MENGE = 90.
W_TEST-DS = '13'.
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 ,' ', W_TEST-DS.
  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.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!