‎2010 Oct 20 10:15 AM
Hi all,
I have a code which fetches the data into an internal table. The content of the internal table is as follows(example):
1) Header 1 amount 1
2) item1 amount 2
3) item1 amount 3
4) item1 amount 4
5) header 1 amount 5
6) item2 amount 6
7) item2 amount 6
😎 item2 amount 6
9) item2 amount 6
10)header1 amount 7
Now i need to modify the code in such a way that the output should add up all the amounts of the header and a line items and should be displayed at the end of the line items as follows.
1) item1 amount 2
2) item1 amount 3
3) item1 amount 4
4) item2 amount 6
5) item2 amount 6
6) item2 amount 6
7) item2 amount 6
8)header1 total amount
I tried using collect statement, but the header is being displayed at line1 and not line 8 where needed.
Please do help me and let me know how best can i modify my code.
In case you are wondering what my req is , it is based on the OB58 configuration.
‎2010 Oct 20 10:25 AM
If you want the first entry of your internal table at last use below code.
read table itab into wa index 1.
if sy subrc eq 0.
delete tab index 1.
append wa to itab.
clear wa.
endif.
‎2010 Oct 20 10:38 AM
HI,
u have told this scenario -->
1) Header 1 amount 1
2) item1 amount 2
3) item1 amount 3
4) item1 amount 4
5) header 1 amount 5
6) item2 amount 6
7) item2 amount 6
😎 item2 amount 6
9) item2 amount 6
10)header1 amount 7
I iam not wrong then i think u want the o/p in this way
1) item1 amount 9
2) item2 amount 24
3)header1 amount 13
But one doubt can there be scenario in this way to if am not wrong
1) Header 1 amount 1
2) item1 amount 2
3) item1 amount 3
4) item1 amount 4
5) header 1 amount 5
6) item2 amount 6
7) item2 amount 6
😎 item2 amount 6
9) item2 amount 6
10)header1 amount 7
11) header 2 amount 5
12) item2 amount 6
13) item2 amount 6
14) item2 amount 6
15) item2 amount 6
16)header2 amount 7
Regards,
Madhukar Shetty
‎2010 Oct 20 1:30 PM
Let me discuss the scenario which Madhukar has described :
if the line items from 1 - 9 belong to header 1 then the amounts of the header 1 as well as the line items from 1-9 must be summed and displayed at line 10.
now the line items from 12 - 15 belong to header 2, so all the amounts of the header 2 as well as the line items from 12-15 shud be summed up and displayed at 16.
‎2010 Oct 20 2:19 PM
Hi,
take one mroe field in the internal table type char, when its an header pass value 'X' to the new field.in loop keep on adding the amounts, finally sort your internal table based on the new field obviously the header will come to the last position.
Thanks,
Vinayaka