SAP/ABAP
COLLECT 구문
Sally_민지
2024. 5. 29. 16:28
최종 작성일: 2024-05-29
목표: Collect 구문 이해하기
*&---------------------------------------------------------------------*
*& Report ZTEST_COLLECT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZTEST_COLLECT.
* internal table Structure creation
"같은 것 끼리 집계하는 것이 collect 문임
TYPES: BEGIN OF t_product,
pid(10) TYPE C,
pname(40) TYPE C,
pamount(10) TYPE P, "pack number (실수)
END OF t_product.
* Data & internal table declaration
DATA: wa TYPE t_product,
it TYPE TABLE OF t_product.
* inserting data to the internal table of INDEX 1
wa-pid = 'IFB1'.
wa-pname = 'IFB WASHING MACHINE'.
wa-pamount = 31000.
COLLECT wa INTO it.
* inserting data to the internal table of INDEX 1
wa-pid = 'IFB1'.
wa-pname = 'IFB WASHING MACHINE'.
wa-pamount = 30000.
COLLECT wa INTO it.
* inserting data to the internal table of INDEX 2
wa-pid = 'IFB2'.
wa-pname = 'IFB SPLIT AC'.
wa-pamount = 38000.
COLLECT wa INTO it.
* inserting data to the internal table of INDEX 2
wa-pid = 'IFB2'.
wa-pname = 'IFB SPLIT AC'.
wa-pamount = 32000.
COLLECT wa INTO it.
* Reading internal table for all the records
LOOP AT it INTO wa.
IF sy-subrc = 0.
WRITE :/ wa-pid, wa-pname, wa-pamount.
ELSE.
WRITE 'No Record Found'.
ENDIF.
ENDLOOP.