2006 Sep 13 11:01 AM
i have a internal table like
material quantity
aa 10
aa 20
aa 10
ab 10
ab 20
ca 30
now i have add all these quatities and modify the same interanl table as
aa 40
ab 30
ca 30.... how to put these contents into the same internal table
2006 Sep 13 11:04 AM
SORT ITAB BY MATNR.
LOOP AT ITAB.
AT END OF MATNR.
SUM.
ITAB2-MATNR = ITAB-MATNR.
ITAB2-QUANTITY = ITAB-QUANTITY.
<b>APPEND ITAB2.</b>
ENDAT.
ENDLOOP.Message was edited by: Srikanth Kidambi
Message was edited by: Srikanth Kidambi
i have a internal table like
material quantity
aa 10
aa 20
aa 10
ab 10
ab 20
ca 30
now i have add all these quatities and modify the same interanl table as
aa 40
ab 30
ca 30.... how to put these contents into the same internal table
2006 Sep 13 11:03 AM
2006 Sep 13 11:03 AM
Hi lokesh,
1. for this, no need to use control-break logic.
2. instead use COLLECT
3. do these steps.
a) create a new internal table STAB
(with two fields, of the same name as original ITAB)
b) LOOP AT ITAB.
STAB = ITAB.
COLLECT STAB.
ENDLOOP.
4. Now your STAB will have total as u require.
<b>Note : If ITAB and STAB have different number of fields,
then use MOVE-CORRESPONDING ITAB TO STAB
instead of STAB = ITAB.</b>
regards,
amit m.
2006 Sep 13 11:04 AM
HI,
data itab1 like itab occurs 0 with header line.
loop at itab.
itab1= itab.
collect itab1.
endloop.
free itab.
itab[] = itab1[]
itab will have
aa 40
ab 30
ca 30....
Regards
amole
2006 Sep 13 11:04 AM
SORT ITAB BY MATNR.
LOOP AT ITAB.
AT END OF MATNR.
SUM.
ITAB2-MATNR = ITAB-MATNR.
ITAB2-QUANTITY = ITAB-QUANTITY.
<b>APPEND ITAB2.</b>
ENDAT.
ENDLOOP.Message was edited by: Srikanth Kidambi
Message was edited by: Srikanth Kidambi
2006 Sep 13 11:04 AM
If you need to put the information in the same table it is better to handle it while you are getting the information into the internal table.
Basically using COLLECT statement instead of APPEND or MODIFY would give you your result.
SELECT * from vbap.
itab-matnr = vbap-matnr.
itab-menge = vbap-menge.
collect itab.
Endselect.
Here the itab would have the data as you required total quantity for each material. Please note that the all C,N type of fields are considered as key in the COLLECT statement.
Message was edited by: Anurag Bankley
2006 Sep 13 11:05 AM
Hi
Loop on your internal table and use collect stmnt to collect data into another internal table.
Regards,
Raj
Eg:
loop at itab1.
move-corresponding itab1 into itab2.
collect itab2.
endloop.
Result in itab2.
2006 Sep 13 11:14 AM
REPORT ZSRIM_TEMP14.
data : begin of itab occurs 0,
matnr type mara-matnr,
quan type i,
end of itab.
data : itab2 like itab occurs 0 with header line.
itab-matnr = '1'.
itab-quan = 2.
append itab.
itab-matnr = '2'.
itab-quan = 2.
append itab.
itab-matnr = '1'.
itab-quan = 2.
append itab.
itab-matnr = '2'.
itab-quan = 2.
append itab.
itab-matnr = '1'.
itab-quan = 2.
append itab.
itab-matnr = '2'.
itab-quan = 2.
append itab.
sort itab by matnr.
BREAK-POINT.
LOOP AT ITAB.
AT END OF MATNR.
SUM.
ITAB2-MATNR = ITAB-MATNR.
ITAB2-QUAN = ITAB-QUAN.
APPEND ITAB2.
ENDAT.
ENDLOOP.
LOOP AT ITAB2.
WRITE :/ ITAB2-MATNR, ITAB2-QUAN.
ENDLOOP.
<b>second method.</b>
instead of LOOP and AT END ..block,you can use COLLECT
LOOP AT ITAB.
ITAB2-MATNR = ITAB-MATNR.
ITAB2-QUAN = ITAB-QUAN.
COLLECT ITAB2.
ENDLOOP.regards
Srikanth
Message was edited by: Srikanth Kidambi
2006 Sep 13 11:29 AM
Hi,
You can loop at your internal table and use
loop at itab.
AT NEW material.
SUM.
endloop.
2006 Sep 13 11:29 AM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |