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

Regarding Collect Statement

Former Member
0 Likes
660

Hi all,

I am Fresher to ABAP.I have a Requirement .

For a Invoice No , i want to COLLECT its Material no , Material Description , Invoice value , Invoice Quantity .

I Used COLLECT Statement FOR this . The Code is Given Below.

LOOP AT IT_DESP.

MOVE-CORRESPONDING IT_DESP TO IT_DESP1.

COLLECT IT_DESP1.

CLEAR: IT_DESP1.

ENDLOOP.

Here i am Populating Invoice No,Material no , Material Description , Invoice value , Invoice Quantity in Internal Table IT_DESP.

The COLLECT statement is not Working Here. Is the above code is Correct are not.

Regards

Sankar

6 REPLIES 6
Read only

Former Member
0 Likes
626

Hi,

I dont see anything worng with your code. Just ensure that all the fields other than those which you want to sum are of char type while using COLLECT.

Vikranth

Read only

Former Member
0 Likes
626

sort it_desp by invoice no before looping.

Read only

Former Member
0 Likes
626

i dont think this code is wrong..

how have you declared the fields of itab1 and itab2?

can you show the definition of these internal tables?

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
626

Dear Sankara,

To provide you an answer why COLLECT is not working we need to have insight on how you have defined the table IT_DESP1.

And for the record, please make it a point of doing an F1 & reading the SAP documentation whenever you are faced with this kind of situation.

BR,

Suhas

Read only

Former Member
0 Likes
626

Hi Sankara ,

Collect statement is used to add all the numeric components to the corresponding values of all the existing rows in an internal table , with the same key . The data type can be I , P , F .

Please ensure that there is a comman value in all the rows .

check this out and let me know if any issues

Regards,

Kavitha

Read only

Former Member
0 Likes
626

hi

why do you need to use collect statement inside the loop. Move statement is already appending the records in the table .

use collect statement after the loop. This will serve the same purpose.

Hope it helps.

Regards

Geeta Gupta