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: 

Re: Internal table.

Former Member
0 Kudos
129

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
109

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.

12 REPLIES 12

Former Member
0 Kudos
109

hi,

u can use collect statement.

reward if useful.

thnks and rgds,

raghul

Former Member
0 Kudos
110

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.

Former Member
0 Kudos
109

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.

Former Member
0 Kudos
109

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

Former Member
0 Kudos
109

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

Former Member
0 Kudos
109

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

Former Member
0 Kudos
109

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..

Former Member
0 Kudos
109

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.

Former Member
0 Kudos
109

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.

Former Member
0 Kudos
109

COLLECT <WA> ... <ITAB> works...

check ..

Regards.

Raju Mummidi.

.

former_member497886
Participant
0 Kudos
109

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.

Former Member
0 Kudos
109

hi,

Your purpose can be solved using COLLECT statement.

It adds all the numeric fields.

Manish