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: 

alternative to collect statement

Former Member
0 Kudos

Hi All!

Can anybody give me the alternative code to collect statement.I mean i want the same functionality as that of collect statement which I want to apply to two numeric columns.Presently using collect I am unable to get the sum of the second column.

Regards

Praneeth

1 ACCEPTED SOLUTION

former_member223537
Active Contributor
0 Kudos

Hi,

Use

loop at itab into wa_tab1.

LOOP AT ITAB into wa_tab2 where field2 = wa_tab1-field2.

l_total = l_total + wa_tab2-field2.

endloop.

wa_tab2-field2 = l_total.

append wa_tab2 to ITAB2.

append

endloop.

ITAB2 would have the summarized data.

Best regards,

Prashant

2 REPLIES 2

Former Member
0 Kudos

The only other alternative is to use variables to count and modify statement.

Basically,

Loop at itab.

at new field1.

clear total.

endat.

total = total + qty.

at end of field1.

read table itab1 with itab.

modify itab1 index sy-tabix.

endat.

Endloop.

Regards

anurag

former_member223537
Active Contributor
0 Kudos

Hi,

Use

loop at itab into wa_tab1.

LOOP AT ITAB into wa_tab2 where field2 = wa_tab1-field2.

l_total = l_total + wa_tab2-field2.

endloop.

wa_tab2-field2 = l_total.

append wa_tab2 to ITAB2.

append

endloop.

ITAB2 would have the summarized data.

Best regards,

Prashant