2008 Jul 20 4:18 PM
Hi,
i have multiple rows with the same date field in an internal table , i need to sum up the amount for the same date. could any body let me know how to do the same.
following is the internal table format.
customer no ,| date | amount
123 | 20080720| 100.00
123 |20080720| 200.00
123 |20080715| 100.00
123 |20080715|500.00
ouput format should be
123 | 20080720|300.00
123|20080715|600.00
Thanks in advance.
2008 Jul 20 4:32 PM
Hi,
If the fields customer no and date are char. type and amount is of type p/f field then use collect statement to achieve ur requirment.
loop at itab.
itab1 = itab.
collect itab1.
endloop.
Here itab (with header line) contains ur entries
itab1 (with header line) will contain ur output.
Regards,
Joy.
2008 Jul 20 4:23 PM
hi,
u can use collect statement.
reward if useful.
thnks and rgds,
raghul
2008 Jul 20 4:32 PM
Hi,
If the fields customer no and date are char. type and amount is of type p/f field then use collect statement to achieve ur requirment.
loop at itab.
itab1 = itab.
collect itab1.
endloop.
Here itab (with header line) contains ur entries
itab1 (with header line) will contain ur output.
Regards,
Joy.
2008 Jul 20 4:42 PM
Hi,
Use the Collect statement on the internal table. It will update the table against the char fields by adding all the numeric fields. For Help press Cltr' + F1 on collect statement in abap editor, it will give you sample code.
Regards,
Naresh.
2008 Jul 20 5:31 PM
Hi Friend,
You can try the following:
itab1 and itab2 are of same structure.
fs_ itab1 - work area(field string) for itab1
loop at itab1.
collect fs_ itab1 into itab2.
endloop.
check this link on COLLECT which has more options:
http://members.tripod.com/sap_abap/collect.htm
Hope this helps you.
Regards,
Chandra Sekhar
2008 Jul 21 5:24 AM
Hi,
U can use the control break statement like..
Loop at itab
Sum = Sum + <amt field>
At end of <date field>
<final itab field name> = sum
Endat.
Endloop.
Reward if useful.
Regards,
Sharin.
Edited by: sharin varghese on Jul 21, 2008 9:55 AM
Edited by: sharin varghese on Jul 21, 2008 9:55 AM
2008 Jul 21 5:27 AM
Hi,
Use COLLECT statement.
It sums up all the numeric value with same key field.
check the link for detail concept.
http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb36d5358411d1829f0000e829fbfe/content.htm
in your case if work area be WA and internal table be itab , the syntax will be
COLLECT wa into itab
Regards,
Anirban
2008 Jul 21 5:28 AM
hi....
you can just use simple collect itab statement.
this statement will help you to sum up the imilar fields and
group them together.
it will add up only the numeric fields and group the other fields..
2008 Jul 21 5:30 AM
Hi,
Try this logic,this will solve ur issue,,,
Loop at ITAB.
At End of date.
Sum.
write : amount. ( it is total amount for corresponding date )
Endat.
Endloop.
Hope it is helps,,,
Regards,
T.Durai murugan.
2008 Jul 21 5:34 AM
Hi,
As also said by others use the COLLECT statement while populating data in the internal table, as it will add all the numeric fields where the key field are similar.
or during displaying the records you can use AT NEW statement like.
LOOP at itab.
AT NEW date.
SUM.
WRITE amount.
ENDAT.
ENDLOOP.
With luck,
Pritam.
2008 Jul 21 5:45 AM
COLLECT <WA> ... <ITAB> works...
check ..
Regards.
Raju Mummidi.
.
2008 Jul 21 5:48 AM
hi,
Use the COllect statement.
Syntax is.
Collect <Internal Table name>.
This sentence internally adds the numeric fields based on the non-numeric fields.
Regards,
Mohammadi.
2008 Jul 21 6:40 AM
hi,
Your purpose can be solved using COLLECT statement.
It adds all the numeric fields.
Manish