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: 

Collect statement

Former Member
0 Kudos
155

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
126

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

11 REPLIES 11

Former Member
0 Kudos
126

I mean wanted to all the weights and have a single line in my internal table.

Shejal.

Former Member
0 Kudos
126

hi,

loop at IT_SEND.

collect IT_SEND into it_send2.

endloop.

IT_SEND 😆 Stands for work area with sum.

Former Member
0 Kudos
126

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

0 Kudos
126

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.

0 Kudos
126

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

0 Kudos
126

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.

0 Kudos
126

Thanks guYS I THING I GOT IT.

Shejal.

Former Member
0 Kudos
126

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

0 Kudos
126

Chandrasekhar,

Would it work even for different materials and if yes how?

Shejal.

0 Kudos
126

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

Former Member
0 Kudos
127

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