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: 

Using AT END OF two times in LOOP....

Former Member
0 Kudos

Hello,

I have a following data in internal table ITAB:

BELNR---AMOUNT----KUNNR

10001---100--


3000

10001---200--


3000

10002---300--


3000

10002---400--


3000

10003---50--


4000

I want to print out like following:

10001--100---3000

10001--200---3000

Total Amount for document 10001 is 300

10002--300----3000

10002--400----3000

Total amount for document 10002 is 700.

______________________________________-

Total amount for customer 3000 is 1000.

_______________________________________

10003--50--


4000

Total amount for document 10002 is 50

____________________________________

Total amount for customer 4000 is 50

____________________________________

I am using following logic but its not working. It still prints Total amount for customer at end of each document number but I want it print at end of customer.

Loop at ITAB:

V_DOC_AMOUNT = V_DOC_AMOUNT + ITAB-AMOUNT.

V_CUST_AMOUNT = V_CUST_AMOUNT + V_DOC_AMOUNT.

AT END OF BELNR.

write:/ 'Total amount for document is', v_DOC_amount.

CLEAR V_DOC_AMOUNT.

ENDAT.

AT END OF KUNNR.

WRITE:/ Total amount for customer is', v_cust_amount.

ENDAT.

ENDLOOP.

Regards,

Rajesh.AT

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

make sure the KUNNR is the first column and BELNR is the second column of your internal table declaration..

sort the internal table by KUNNR BELNR..before the loop..

Thanks

Naren

1 REPLY 1

Former Member
0 Kudos

Hi,

make sure the KUNNR is the first column and BELNR is the second column of your internal table declaration..

sort the internal table by KUNNR BELNR..before the loop..

Thanks

Naren