Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Help using collect statement

Former Member
0 Kudos

TABLES: EKKO, LFA1, EKPO.

TYPES: BEGIN OF ST_HEADER,

EBELN LIKE EKKO-EBELN,

LIFNR LIKE LFA1-LIFNR,

NAME1 LIKE LFA1-NAME1,

AEDAT LIKE EKKO-AEDAT,

ERNAM LIKE EKKO-ERNAM,

END OF ST_HEADER,

BEGIN OF ST_DETAIL,

EBELN LIKE EKKO-EBELN,

EBELP LIKE EKPO-EBELP,

TXZ01 LIKE EKPO-TXZ01,

NETWR LIKE EKPO-NETWR,

END OF ST_DETAIL.

DATA: WA_HEADER1 TYPE TABLE OF ST_HEADER,

WA_HEADER2 TYPE TABLE OF ST_HEADER,

WA_HEADERT TYPE TABLE OF ST_HEADER,

WA_DETAIL1 TYPE TABLE OF ST_DETAIL,

WA_DETAIL2 TYPE TABLE OF ST_DETAIL,

WA_DETAILT TYPE TABLE OF ST_DETAIL WITH HEADER LINE.

FIELD-SYMBOLS: <HD1> TYPE ST_HEADER,

<HD2> TYPE ST_HEADER,

<HD3> TYPE ST_HEADER,

<DT1> TYPE ST_DETAIL,

<DT2> TYPE ST_DETAIL,

<DT3> TYPE ST_DETAIL.

SELECT-OPTIONS: S_EBELN FOR EKKO-EBELN.

SELECT-OPTIONS: S_LIFNR FOR LFA1-LIFNR.

SELECT *

FROM EKKO

INTO CORRESPONDING FIELDS OF TABLE WA_HEADER1.

SELECT *

FROM LFA1

INTO CORRESPONDING FIELDS OF TABLE WA_HEADER2.

LOOP AT WA_HEADER1 ASSIGNING <HD1>.

LOOP AT WA_HEADER2 ASSIGNING <HD2>.

IF <HD1>-LIFNR EQ <HD2>-LIFNR.

APPEND INITIAL LINE TO WA_HEADERT ASSIGNING <HD3>.

<HD3>-EBELN = <HD1>-EBELN.

<HD3>-LIFNR = <HD2>-LIFNR.

<HD3>-NAME1 = <HD2>-NAME1.

<HD3>-AEDAT = <HD1>-AEDAT.

<HD3>-ERNAM = <HD1>-ERNAM.

ENDIF.

ENDLOOP.

ENDLOOP.

SELECT *

FROM EKKO

INTO CORRESPONDING FIELDS OF TABLE WA_DETAIL1.

SELECT *

FROM EKPO

INTO CORRESPONDING FIELDS OF TABLE WA_DETAIL2.

LOOP AT WA_DETAIL1 ASSIGNING <DT1>.

LOOP AT WA_DETAIL2 ASSIGNING <DT2>.

IF <DT1>-EBELN EQ <DT2>-EBELN.

APPEND INITIAL LINE TO WA_DETAILT ASSIGNING <DT3>.

<DT3>-EBELN = <DT1>-EBELN.

<DT3>-EBELP = <DT2>-EBELP.

<DT3>-TXZ01 = <DT2>-TXZ01.

<DT3>-NETWR = <DT2>-NETWR.

ENDIF.

ENDLOOP.

ENDLOOP.

LOOP AT WA_HEADERT ASSIGNING <HD1>.

WRITE: / <HD1>-EBELN COLOR COL_KEY,

<HD1>-LIFNR COLOR COL_GROUP,

<HD1>-NAME1 COLOR COL_GROUP,

<HD1>-AEDAT COLOR COL_GROUP,

<HD1>-ERNAM COLOR COL_GROUP.

AT END OF EBELN.

LOOP AT WA_DETAILT ASSIGNING <DT1>.

IF <HD1>-EBELN = <DT1>-EBELN.

WRITE: / ' ',

<DT1>-EBELP,

<DT1>-TXZ01,

<DT1>-NETWR.

ENDIF.

ENDLOOP.

ENDAT.

ENDLOOP.

Help!!

I need to get the sum of netwr of <dt1>-netwr but I couldn't use SUM as it forbids me when I'm using loop...assigning....I'm not so familiar with using Collect statement to get the sum of netwr.

the output is I got a header data then details..after all the details of a particular header comes the total.

regards,

Lawrence

1 REPLY 1

Former Member
0 Kudos

Just discovered my answer though not using COLLECT statement

I declared additional data objects

PREVIOUS LIKE EKKO-EBELN,

CURRENT LIKE EKKO-EBELN,

AMOUNT LIKE EKPO-NETWR.

and edited my detail loop

LOOP AT WA_DETAILT ASSIGNING <DT1>.

IF <HD1>-EBELN = <DT1>-EBELN.

AMOUNT = AMOUNT + <DT1>-NETWR.

WRITE: / ' ',

<DT1>-EBELP,

<DT1>-TXZ01,

<DT1>-NETWR.

AT END OF EBELN.

WRITE : / 'TOTAL : ' , AMOUNT.

CLEAR AMOUNT.

ENDAT.