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 up the values

Former Member
0 Kudos

data : begin of itab,

n(3) type c,

n1 type n,

n2 type n,

k(5) type c,

end of itab.

select n n1 n2 k from into itab from table /zteest.

*internal table has

n n1 k n2

gar 100 uji 2

hae 90 iou 3

gar 90 uji 3

hae 87 iou 4

I want

gar 190 uij 5

hae 177 iou 7

How to use collect statement as n1 is n ..?

I want to sum up n1 and n2 if value of k and n is same

Thanks

2 REPLIES 2

naimesh_patel
Active Contributor
0 Kudos

Make one more internal table and use the collect.

DATA: BEGIN OF IT_SUM,
N(3) TYPE C,
N1 TYPE I,  " << should be I, P or F to get sum for that field
K(5) TYPE C,
N2 TYPE I,
END OF IT_SUM.

LOOP AT ITAB.
 MOVE-CORESSPONDING ITAB TO IT_SUM.
 COLLECT IT_SUM.
 CLEAR   IT_SUM.
ENDLOOP.

Regards,

Naimesh Patel

Former Member
0 Kudos

Hi,

Declare a work area and another internal table same as itab. And declare n1 and n2 as Integer type and if you have decimals declare it as type p decimals 2.

Use below code :

data : wa_like line of itab,

itab1 like itab occurs 0 with header line.

Here comes to your select table.

Once table is loaded into itab.

Use the below code to sum up.

Loop at itab into wa.
collect wa to newitab.
endloop.

Thanks,

Sriram Ponna.