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: 

Internal Table

Former Member
0 Kudos

Hi All,

I have internal table like

sno matnr amount

1 XX 1

2 XY 1

3 XY 5

4 XZ 3

5 XX 4

6 XX 6

7 XY 6

i want internal table like Sum(amount) of all matnr and internal table now becomes :

sno matnr amount

1 XX 11

2 XY 12

3 XZ 3

Any suggestions welcome.

Regards,

Edited by: Navdeep singh on Dec 25, 2007 11:45 AM

5 REPLIES 5

Former Member
0 Kudos

Hi,

Check the below logic:

data: begin of itab,

matnr type matnr,

amount type .....

end of itab.

SORT itab by matnr.

loop at itab.

at end of matnr.

sum.

itab1-matnr = itab-matnr.

itab1-amount = itab-amount.

append itab1.

clear: itab1.

end at.

endloop.

display itab1. u will get required result.

internal table structure should contain only matnr and amount. dont use sno. if you want to use it, make it as second or third field in the internal table.

0 Kudos

Thanks to all ,

Probem resolved !!!!!!!!!!!!

Regards,

Former Member
0 Kudos

HI,

see this code.

data:begin of itab OCCURS 0,

no(2) type n,

matnr like mara-matnr,

amt(10) type n,

END OF itab.

data:begin of jtab OCCURS 0,

no(2) type n,

matnr like mara-matnr,

amt(10) type n,

END OF jtab.

data:sum_amt(10) type n,

v_no(2) type n.

<fill internal table>

SORT itab by matnr.

loop at itab.

at new matnr.

clear sum_amt.

ENDAT.

sum_amt = sum_amt + itab-amt.

at end of matnr.

v_no = v_no + 1.

jtab-no = v_no.

jtab-matnr = itab-matnr.

jtab-amt = sum_amt.

append jtab.

ENDAT.

ENDLOOP.

rgds,

bharat.

Former Member
0 Kudos

Hi ,

with this code you can do summation for each and material number.....

types : begin of i_amount,

sno(3) type c,

matnr(10) type c,

amount(10) type c,

end of i_amount.

data : wa type i_amount,

itab type table of i_amount.

wa-sno = 1.

wa-matnr = 'XX'.

wa-amount = 1.

append wa to itab.

wa-sno = 2.

wa-matnr = 'XY'.

wa-amount = 1.

append wa to itab.

wa-sno = 3.

wa-matnr = 'XY'.

wa-amount = 5.

append wa to itab.

wa-sno = 4.

wa-matnr = 'XZ'.

wa-amount = 3.

append wa to itab.

wa-sno = 5.

wa-matnr = 'XX'.

wa-amount = 4.

append wa to itab.

wa-sno = 6.

wa-matnr = 'XX'.

wa-amount = 6.

append wa to itab.

wa-sno = 7.

wa-matnr = 'XY'.

wa-amount = 6.

append wa to itab.

loop at itab into wa.

at new matnr.

write 😕 wa-sno,wa-matnr,wa-amount.

endat.

at end of matnr.

sum.

write :/'total amount =', wa-amount.

endat.

endloop.

regards,

swami

Former Member
0 Kudos

Hi,

Follow the following code.

Data: begin of itab1 occurs 0,

sln type c,

matnr type matnr,

amount type p decimals 2,

end of itab.

***from ur int table where matnr, sno, amount**********

Loop at itab.

move-corresponding itab to itab1.

collect itab1.

clear itab.

endloop.

data: count type i.

count = 0.

Loop at itab1.

count = count + 1

itab1-sln = count.

modify itab1.

endloop.

It will work fine.

If it is helpfull pls reward pts.

Regards

Srimanta