2007 Sep 17 4:03 PM
Hello Gurus,
I have an internal table with data in it. The fields of the internal table are
Location - Matnr - Qty - Flag.
Same material can be at different locations with different quantities. I need to get material and total quantity of the material in all the locations in a new internal table.
If the table (it_tab) contains -
Location - matnr - qty - flag
1200 abc 10 S
1201 abc 20 S
1205 abc 30 S
1207 abc 50 S
1200 xyz 20 S
1201 xyz 25 S
1300 xyz 22 S
From this table, I need to get the result int table (it_res) as below -
Matnr - qty
abc 110
xyz 67
110 = 102030+50
67 = 252220
My idea is we can use collect statement looping the it_tab table.
Please help me how to do this.
Regards,
Balu
2007 Sep 17 4:20 PM
Hi balu,
1. Simple
2. Create one another internal table STAB,
with only two fields
a) MATNR
b) QTY
3. Now,
4.
Loop at Itab.
Move-corresponding itab to STAB.
COLLECT STAB.
Endloop.
regards,
amit m.
Hi balu,
1. Simple
2. Create one another internal table STAB,
with only two fields
a) MATNR
b) QTY
3. Now,
4.
Loop at Itab.
Move-corresponding itab to STAB.
COLLECT STAB.
Endloop.
regards,
amit m.
2007 Sep 17 4:07 PM
Hi,
Please try this.
sort it_tab by matnr ascending.
loop at it_tab.
it_res-matnr = it_tab-matnr.
it_res-qty = it_tab-qty.
collect it_res.
endloop.
...
Regards,
Ferry Lianto
2007 Sep 17 4:20 PM
Hi balu,
1. Simple
2. Create one another internal table STAB,
with only two fields
a) MATNR
b) QTY
3. Now,
4.
Loop at Itab.
Move-corresponding itab to STAB.
COLLECT STAB.
Endloop.
regards,
amit m.
2007 Sep 17 5:40 PM
Thanks Ferry and Amit.
For some reason I am not getting the required out put.
I am getting the output as single entries for the repeated materials but the quantity is not being added up.
loc - mat - qty - flag
10 abc 10 s
20 xyz 10 s
30 abc 10 s
40 xyz 10 s
50 abc 50 s
30 xyz 50 s
I am getting the output as -
mat - qty
abc 10
abc 50
xyz 10
xyz 50
But I need as
abc 70
xyz 70
Any suggestions.
Regards,
Balu
2007 Sep 17 5:48 PM
Hi Balu,
If you want the qty to be added, I believe that the field in your internal table should be defined as a numeric field.
Hope it helps.
Regards,
Gilberto Li
2007 Sep 25 3:02 AM
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |