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 not adding and mergeing

pritam_baboo
Participant
0 Kudos

Hi All,

I have an Internal table with fields that I want to add and merge. For ex:

plant bomID matnr idnrk menge vornr plnnr

1100 1028-02 111222 11122205 100 31 5555-1

1100 1028-02 111222 11122205 200 33 5555-2

1100 1028-01 111222 11122203 200 34 5555-2

1100 1028-01 111222 11122203 200 33 5555-2

1100 1028-02 111222 11122201 100 33 5555-2

Now I want to add the MENGE field(it is type p) according to idnrk and result should be

plant bomID matnr idnrk menge vornr plnnr

1100 1028-02 111222 11122205 300 31 5555-1

1100 1028-02 111222 11122203 400 33 5555-2

1100 1028-01 111222 11122201 100 33 5555-2

I am using collect statement but it is not working. Kindly suggest

5 REPLIES 5

FredericGirod
Active Contributor

Why do you say it didn't work?

what is the result ? what is the code used ?

Sandra_Rossi
Active Contributor

COLLECT statement "adds and merges" very well in the conditions explained in the ABAP documentation.

1. Collect statement could not collect the data according to a specific field( Ex: In you case menge could not be collected for IDNRK only)

2. In your structure collect statement collect the menge according to below highlighted fields.

plant bomID matnr idnrk menge vornr plnnr

Hence collect statement won't fulfill your requirement

3. Solution :Try to use the structure with less no.of fields if possible and use collect. Or use loop statement and add menge.


pritam_baboo
Participant
0 Kudos

The Collect statement is just adding up but line items are not merging. As stated by Rama Chittimadi, Thanks for the inputs. I am using loop statement.

venkateswaran_k
Active Contributor

Hi Preetham

Collect statement is like a Group by Clause in SQL.

So for each combination of

Plant + BomID + Material + Maerial(idnrk) + vornr + plnnr == sum(menge).

So if you want on any specific one , then you need to handle other also not chaning.