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

Manipulation in a internal table

Former Member
0 Likes
744

Hi,

I have one internal table with NETWR value with other fields.

now i have netwr values as 10,20,30,40.

Then i should sum up NETWR value for internal table on a single hit.

Can anybody have the solution.

Right now i am looping at that I.Table and calculating sum of all NETWR's.

Any other solution!

Thanks,

Prasad.

Hi,

I have one internal table with NETWR value with other fields.

now i have netwr values as 10,20,30,40.

Then i should sum up NETWR value for internal table on a single hit.

Can anybody have the solution.

Right now i am looping at that I.Table and calculating sum of all NETWR's.

Any other solution!

Thanks,

Prasad.

6 REPLIES 6
Read only

Former Member
0 Likes
690

select netwr into lv_netwr from vbrk

where cond....

gv_netwr = gv_netwr + lv_netwr

endselect.

write: gv_netwr.

Read only

Former Member
0 Likes
690

Use SUM Option check the exact syntax using F1

Read only

Former Member
0 Likes
690

If you have values in different fields of the table, then summing up inside the loop is the solution.

Regards,

Ravi

Read only

Former Member
0 Likes
690

Hi,

Had you checked the COLLECT Statement.

Regards,

Raghav

Read only

Former Member
0 Likes
690

Hi,

i think loop is the only solution.

to optimize u can use sum in a loop

loop at itab.

at end of <Field name>

sum.

append value in some other table.

endat.

endloop.

for that field_name should be first field and sorted.

mark Helpfull Answers

Regards

Read only

Former Member
0 Likes
690

Hi,

If you want to sum up the NETWR based on some condition then you can write the code like this.

Loop at Itab where <condition>

COLLECT itab INTO i_final.

Endloop.

or

Loop at Itab.

if <condition>

COLLECT itab INTO i_final.

Endif.

Endloop.

OR

If you want to sum up these NETWR based on Document number for example PO# then you need to write like this.

Sort itab[] by order_number.

loop at itab.

at new order_number.

loop at itab where order_number = itab-order_number.

Collect itab into i_final.

endloop.

endat.

endloop.

Cheers,

Bujji.