2008 Jan 09 11:47 AM
hi ,
i have an internal table final which has kunnr and value .
i need kunnr wise total .what is the code.
e.g)
kunnr value
10 10000
20 50000
10 30000
30 40000
output shopuld be
10 13000
20 50000
30 40000
what shall i do??
mani
hi ,
i have an internal table final which has kunnr and value .
i need kunnr wise total .what is the code.
e.g)
kunnr value
10 10000
20 50000
10 30000
30 40000
output shopuld be
10 13000
20 50000
30 40000
what shall i do??
mani
2008 Jan 09 11:49 AM
Hi,
Do as below :
Declare a workarea and do as below :
Loop at itab into wa.
collect wa to itab1.
endloop.
Thanks,
Sriram Ponna
2008 Jan 09 11:49 AM
Hi Mani
Say your entries are in table itab. Here's the code
**************************************
Sort itab by Kunnr.
loop at itab.
l_amount = l_amount + itab-value.
at end of kunnr.
write : / itab-kunnr, l_amount.
clear l_amount.
endat.
endloop.
****************************
Hope this helps !
~ Ranganath
2008 Jan 09 11:50 AM
Hi,
declare one more internal table as same type n use collect statement
loop at itab1.
collect itab1 to itab2.
endloop.
Regards,
Prashant
2008 Jan 09 11:53 AM
Hello,
Have a look at COLLECT statement:
Syntax
COLLECT wa INTO itab (result).
Effect
This statement inserts the contents of a work area wa either as single row into an internal table itab or adds the values of its numeric components to the corresponding values of existing rows with the same key. As of Release 6.10, you can use result to set a reference to the inserted or changed row in the form of a field symbol or data reference.
I hope it will help you.
2008 Jan 09 11:55 AM
Hi Manikandhan,
The following explanation might help u out..
Use COLLECT statement
Syntax: COLLECT [<wa> INTO] <itab>.
Note:
1.Use COLLECT statement for tables having unique standard keys.
2.Incase of tables with header line omit INTO option.
3.If an entry with same standard key exists new line is not appended but adds the numeric fields to existing contents.
4.Else collect acts in a similar way as append.
5.Sy-tabix contains the index of the processed line.
Here is a sample code which gives u an idea ...
Example:
Data: Begin of itab occurs 3,
column1(3) type C,
column2(2) type N,
column3 type I,
End of itab.
itab-column1 = abc.
itab-column2 = 12.
itab-column3 = 3.
collect itab.
itab-column1 = def.
itab-column2 = 34.
itab-column3 = 5.
collect itab.
itab-column1 = abc.
itab-column2 = 12.
itab-column3 = 7.
collect itab.
Loop at itab.
write :/itab-column1,
itab-column2,
itab-column3.
Endloop.
OUTPUT: abc 12 10
def 34 5
Reward if helpful.
Thankyou,
Regards.
2008 Jan 09 12:04 PM
Hi mani,
Use the following code.
data: itab1 like itab occurc 0 with header line.
after all select statement.
sort itab by kunnr.
loop at itab.
move-corresponding itab to itab1.
collect itab.
endloop.
output will be
kunnr total value
10 40000
20 50000
30 40000
If it is helpfull pls do reward pts.
Regards
Srimanta
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |