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

Problem with Collect statement

Former Member
0 Likes
980

Hi Experts,

I am facing a peculiar problem. Please go through the code below and it is not giving the aggregate of it_ekbe_642_pgi-menge for the same it_ekbe_642_pgi-ebeln and it_ekbe_642_pgi-ebelp.

LOOP AT it_ekbe_642_pgi.

it_ekbe_642_pgi_tot-ebeln = it_ekbe_642_pgi-ebeln.

it_ekbe_642_pgi_tot-ebelp = it_ekbe_642_pgi-ebelp.

it_ekbe_642_pgi_tot-budat = it_ekbe_642_pgi-budat.

it_ekbe_642_pgi_tot-xblnr = it_ekbe_642_pgi-xblnr.

it_ekbe_642_pgi_tot-menge = it_ekbe_642_pgi-menge.

COLLECT it_ekbe_642_pgi_tot.

ENDLOOP.

Please suggest.

Thanks....

Shibaji.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
958

hi,

Declare internal table fields datatyps should be same as database fields which you are referring.

one more point is if you are not considering xblnr for cumulation of quantites dont put that in loop while using collect stmt.

afterwards you move xblnr with modify stmt into 2nd internal table.

when budat is also same only (not only ebeln ebelp ) qty will be cumulated.

Regds

Sivaparvathi

Please reward points if helpful.

9 REPLIES 9
Read only

JackGraus
Active Contributor
0 Likes
958

Table EKBE holds the receipt documents for a purchase order. When you have several receipts on a purchase order item but with a different posting date (BUDAT) or reference (XBLNR) the collect statement will create a new record in yoy internal table. Only numeric fields are aggregated.

regards Jack

Read only

Former Member
0 Likes
958

Hi Jack,

I wanted to aggregate the numeric field (menge) with same ebeln, ebelp, budat and with different xblnr. But, it is overwriting on the previous record.

Please tell me the problem in the code..

Regards,

Shibaji.

Read only

JackGraus
Active Contributor
0 Likes
958

Then XBLNR should be left blank otherwise different references (XBLNR) will result in different records in your internal table.

Regards Jack

Read only

Former Member
0 Likes
958

Hi Jack,

I wanted to aggregate the numeric field (menge) with same ebeln, ebelp, budat and with different xblnr. But, it is overwriting on the previous record.

Please tell me the problem in the code..

Regards,

Shibaji.

Read only

JackGraus
Active Contributor
0 Likes
958

Your internal table definition of it_ekbe_642_pgi_tot-menge might not be numeric ?

Regards Jack

Read only

Former Member
0 Likes
959

hi,

Declare internal table fields datatyps should be same as database fields which you are referring.

one more point is if you are not considering xblnr for cumulation of quantites dont put that in loop while using collect stmt.

afterwards you move xblnr with modify stmt into 2nd internal table.

when budat is also same only (not only ebeln ebelp ) qty will be cumulated.

Regds

Sivaparvathi

Please reward points if helpful.

Read only

0 Likes
958

Thank you all ... my problem got resolved.

Regards,

Shibaji

Read only

former_member402443
Contributor
0 Likes
958

Hi Shibaji Maitra ,

Since you are aggregating the it_ekbe_642_pgi-menge for the same it_ekbe_642_pgi-ebeln and it_ekbe_642_pgi-ebelp.

For using the Collect statement the order of the fields should be

in proper order i.e. all the char fields come up & then after that

all the numeric fields.Please check the sequence in your internal

table and also the fields type of menge field.

LOOP AT it_ekbe_642_pgi.

it_ekbe_642_pgi_tot-ebeln = it_ekbe_642_pgi-ebeln.

it_ekbe_642_pgi_tot-ebelp = it_ekbe_642_pgi-ebelp.

it_ekbe_642_pgi_tot-xblnr = it_ekbe_642_pgi-xblnr.

it_ekbe_642_pgi_tot-budat = it_ekbe_642_pgi-budat.

it_ekbe_642_pgi_tot-menge = it_ekbe_642_pgi-menge.

COLLECT it_ekbe_642_pgi_tot.

ENDLOOP.

Rewards points if helpful.

Regards

Manoj Kumar

Read only

Former Member
0 Likes
958

hai Shibaji Maitra,

i think ur problem is to collect the fields only when xblnr is changed.if it is right u must use on change of bcz the collect statement collects the field when a single value of left of ur field (it_ekbe_642_pgi_tot) which u are going to collect(it_ekbe_642_pgi_tot) changes.

i think this might be usefull for u.....