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
708

Hi , what is collect statement, can any one explain me with an example...

thanks in advance

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
670

Hi Praveen,

Collect statement inserts contents of a work area into an internal table if a record with same key combination does not exist. But, if the same key combination exists, it adds the values of its numeric components to the corresponding values of existing rows with the same key.

i.e. if your internal table contains

A 100

B 100

Now, if you try to collect C 100, your internal table will look like

A 100

B 100

C 100

Now, if you try to collect C 200, then your internal table will look like

A 100

B 100

C 300.

Reward points if the answer is helpful.

Regards,

Mukul

5 REPLIES 5
Read only

Former Member
0 Likes
670

Have you checked the ABAP help for this?

Rob

Read only

Former Member
0 Likes
670

say u have 10 line items and u want to have common line items as such then u use collect statement.

say, internal table has material and quantity.

aaa 10

aaa 20

bbb 5

ccc 8

bbb 3

aaa 5

bbb 7

so, if u want only rows as

aaa qty

bbb qty

ccc qty

sort itab by material.

loop at itab.

itab1-material = itab-material.

itab1-qty = itab-qty.

collect itab1.

endloop.

so, itab1 will have

aaa 35

bbb 15

ccc 8

hope u understood the concept.

Reward Points...

Read only

Former Member
0 Likes
671

Hi Praveen,

Collect statement inserts contents of a work area into an internal table if a record with same key combination does not exist. But, if the same key combination exists, it adds the values of its numeric components to the corresponding values of existing rows with the same key.

i.e. if your internal table contains

A 100

B 100

Now, if you try to collect C 100, your internal table will look like

A 100

B 100

C 100

Now, if you try to collect C 200, then your internal table will look like

A 100

B 100

C 300.

Reward points if the answer is helpful.

Regards,

Mukul

Read only

Former Member
0 Likes
670

Hi Praveen,

collect stamets compares the non numerical fields and adds the corr numerical fields. simply

aa 12

ab 13

aa 15

aa 23

ac 21

ab 15

ac 10

after collect statement u wil get the o/p like this

aa 50

ab 28

ac 31

Read only

0 Likes
670

Hey thanks alot man,,, ill keep in touch with u in the future..

thank you