2006 Jun 27 3:16 PM
Hi Friends,
I have many line in an internal table but have the same IT_SEND.
I have the same materials etc.. in all the lines. However the weight differs in every line. SO just wanted to add all weights.
I am using
loop at IT_SEND.
collect IT_SEND.
endloop.
Is this correct.
Shejal.
2006 Jun 27 3:24 PM
Hi Shejal,
Take another internal table and move matnr and totals for same matnr into it.Whenever performing COLLECT, it is better to take another internal table to store result values of COLLECT.
<b>DATA: BEGIN OF ITAB,
MATNR LIKE MARA-MATNR,
WEIGHT LIKE MARA-BRGEW,
END OF ITAB.
LOOP AT IT_SEND.
MOVE-CORRESPONDING IT_SEND TO ITAB.
COLLECT ITAB.
ENDLOOP.</b>
Thanks,
Vinay
2006 Jun 27 3:17 PM
I mean wanted to all the weights and have a single line in my internal table.
Shejal.
2006 Jun 27 3:18 PM
hi,
loop at IT_SEND.
collect IT_SEND into it_send2.
endloop.
IT_SEND 😆 Stands for work area with sum.
2006 Jun 27 3:18 PM
Hi
I think so, the collect sums all number fields for the record with the same values for the char fields.
But you should use another table:
loop at IT_SEND into IT_SEND2.
collect IT_SEND.
endloop.
Or you use the COLLECT statament while appending the record into IT_SEND.
Max
2006 Jun 27 3:19 PM
HOwever if i have different materials and i still want to add the weights of all the materials irrespective of what the material is.
Shejal.
2006 Jun 27 3:21 PM
In that case you cannot use the COLLECT statement as it is dependent on having the same key of the char fields in the table.
In this case you will have to write the logic yourself for totalling.
regards
Ravi
2006 Jun 27 3:25 PM
Hi,
Yes it will work.
alternative solution.
wa_temp.
loop at itab.
wa_temp-material = itab-material.
sum.
at end of material.
wa_temp-weight = itab-weight.
append wa_temp into itab2.
endat.
endloop.
2006 Jun 27 3:28 PM
2006 Jun 27 3:21 PM
if the fields u have in the table are MATNR and weight fields only, COLLECT will work,
if u have different materials also it will work
Message was edited by: Chandrasekhar Jagarlamudi
2006 Jun 27 3:24 PM
Chandrasekhar,
Would it work even for different materials and if yes how?
Shejal.
2006 Jun 27 3:31 PM
Hi Shejal,
COLLECT will add all numeric values, if all other non-numeric values (Character values) are same.
In your case you have only matnr and weight,So it holds good for all different materials.
Thanks,
Vinay
2006 Jun 27 3:24 PM
Hi Shejal,
Take another internal table and move matnr and totals for same matnr into it.Whenever performing COLLECT, it is better to take another internal table to store result values of COLLECT.
<b>DATA: BEGIN OF ITAB,
MATNR LIKE MARA-MATNR,
WEIGHT LIKE MARA-BRGEW,
END OF ITAB.
LOOP AT IT_SEND.
MOVE-CORRESPONDING IT_SEND TO ITAB.
COLLECT ITAB.
ENDLOOP.</b>
Thanks,
Vinay