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: 

Sum value without using collect

Former Member
0 Kudos

Hey folks,

i have records and i have to sum them up modify the table by inserting the sum value without using collect. how can i do it ..

for example

table itab contains

1

2

3

4

5

i have to modify this table and insert the sum value like itab shud contain 15 only but without using the collect statemnt . could somebody write me a sample code for this.

Regards

Rock

Edited by: Alvaro Tejada Galindo on Jan 30, 2008 3:13 PM

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Are you saying that you want to find the sum and then replace the individual entries with just a sum entry? If that is the case, you could use something like this:

LOOP AT itab INTO wa_itab.

ADD wa_itab-field1 to field1_sum.

ENDLOOP.

CLEAR itab.

wa_itab-field1 = field1_sum.

APPEND wa_itab TO itab.

If you just want to add a record for the sum (without deleting the others), just remove the CLEAR statement. I hope this helps.

- April King

1 REPLY 1

Former Member
0 Kudos

Are you saying that you want to find the sum and then replace the individual entries with just a sum entry? If that is the case, you could use something like this:

LOOP AT itab INTO wa_itab.

ADD wa_itab-field1 to field1_sum.

ENDLOOP.

CLEAR itab.

wa_itab-field1 = field1_sum.

APPEND wa_itab TO itab.

If you just want to add a record for the sum (without deleting the others), just remove the CLEAR statement. I hope this helps.

- April King