Application Development and Automation 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: 
Read only

Collect statement

Former Member
0 Likes
1,104

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
Read only

Former Member
0 Likes
1,075

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
Read only

Former Member
0 Likes
1,075

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

Shejal.

Read only

Former Member
0 Likes
1,075

hi,

loop at IT_SEND.

collect IT_SEND into it_send2.

endloop.

IT_SEND 😆 Stands for work area with sum.

Read only

Former Member
0 Likes
1,075

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

Read only

0 Likes
1,075

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.

Read only

0 Likes
1,075

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

Read only

0 Likes
1,075

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.

Read only

0 Likes
1,075

Thanks guYS I THING I GOT IT.

Shejal.

Read only

Former Member
0 Likes
1,075

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

Read only

0 Likes
1,075

Chandrasekhar,

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

Shejal.

Read only

0 Likes
1,075

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

Read only

Former Member
0 Likes
1,076

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