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

Sum on a internal table

Former Member
0 Likes
948

Hi All,

I have internal table like this.

Field1 Field2 Field3

a 1 5.000

b 1 5.000

b 1 3.000

b 1 10.000

b 1 10.000

b 2 15.000

c 1 10.000

c 2 10.000

Now i have to sum field3 based on field1 and field2 i.e My Output will be like this.

Field1 Field2 Field3

a 1 5.000

b 1 28.000

b 2 15.000

c 1 10.000

c 2 10.000.

Please suggest some solution as I guess this output is not possible thru At end of or at new.

We can get the desired output using on change of but the summation is not possible thru on change of.

Thanks and regards

Nazmul Azad

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
916

Hi,

Please refer the below program:

data : var(20) type c,

var1(20) type c,

var2(20) type c.

data : begin of itab occurs 0,

f1 type c,

f2 type i,

f3 type i,

end of itab.

itab-f1 = 'a'.

itab-f2 = '1'.

itab-f3 = '5'.

append itab.

clear itab.

itab-f1 = 'b'.

itab-f2 = '1'.

itab-f3 = '5'.

append itab.

clear itab.

itab-f1 = 'b'.

itab-f2 = '1'.

itab-f3 = '3'.

append itab.

clear itab.

itab-f1 = 'b'.

itab-f2 = '1'.

itab-f3 = '10'.

append itab.

clear itab.

itab-f1 = 'b'.

itab-f2 = '2'.

itab-f3 = '15'.

append itab.

clear itab.

itab-f1 = 'c'.

itab-f2 = '1'.

itab-f3 = '10'.

append itab.

clear itab.

itab-f1 = 'c'.

itab-f2 = '2'.

itab-f3 = '10'.

append itab.

clear itab.

//Sorted based on field1 and field2 and used At new

sort itab by f1 f2.

loop at itab.

at new f2.

sum.

endat.

endloop.

Best Regards,

Sumana

Hi All,

I have internal table like this.

Field1 Field2 Field3

a 1 5.000

b 1 5.000

b 1 3.000

b 1 10.000

b 1 10.000

b 2 15.000

c 1 10.000

c 2 10.000

Now i have to sum field3 based on field1 and field2 i.e My Output will be like this.

Field1 Field2 Field3

a 1 5.000

b 1 28.000

b 2 15.000

c 1 10.000

c 2 10.000.

Please suggest some solution as I guess this output is not possible thru At end of or at new.

We can get the desired output using on change of but the summation is not possible thru on change of.

Thanks and regards

Nazmul Azad

4 REPLIES 4
Read only

Former Member
0 Likes
916

Look into COLLECT statement.

Read only

Former Member
0 Likes
917

Hi,

Please refer the below program:

data : var(20) type c,

var1(20) type c,

var2(20) type c.

data : begin of itab occurs 0,

f1 type c,

f2 type i,

f3 type i,

end of itab.

itab-f1 = 'a'.

itab-f2 = '1'.

itab-f3 = '5'.

append itab.

clear itab.

itab-f1 = 'b'.

itab-f2 = '1'.

itab-f3 = '5'.

append itab.

clear itab.

itab-f1 = 'b'.

itab-f2 = '1'.

itab-f3 = '3'.

append itab.

clear itab.

itab-f1 = 'b'.

itab-f2 = '1'.

itab-f3 = '10'.

append itab.

clear itab.

itab-f1 = 'b'.

itab-f2 = '2'.

itab-f3 = '15'.

append itab.

clear itab.

itab-f1 = 'c'.

itab-f2 = '1'.

itab-f3 = '10'.

append itab.

clear itab.

itab-f1 = 'c'.

itab-f2 = '2'.

itab-f3 = '10'.

append itab.

clear itab.

//Sorted based on field1 and field2 and used At new

sort itab by f1 f2.

loop at itab.

at new f2.

sum.

endat.

endloop.

Best Regards,

Sumana

Read only

0 Likes
916

Thanks Sumana...your suggestion solved my issue..

Nazmul

Read only

Former Member
0 Likes
916

Hi,

Search the forum before asking the basic questions.