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: 

itab sum calculation

Former Member
0 Kudos

friends,

i have aproblem,

the following can make you understand better.

name marks

-


john 20

john 30

john 40

martin 30

smith 20

martin 20

smith 10

this itab1 must be converted to itab2 given below

name marks

_______________________________

john 90(=203040)

martin 50(=30+20)

smith 30(=20+10)

what would be the best way of coding.

thank you.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi saritha,

loop at itab1.

itab2-name = itab1-name.

itab2-marks = itab1-marks.

collect itab2.

endloop.

Reward points if useful.

Regards,

Atish

5 REPLIES 5

Former Member
0 Kudos

Hi saritha,

loop at itab1.

itab2-name = itab1-name.

itab2-marks = itab1-marks.

collect itab2.

endloop.

Reward points if useful.

Regards,

Atish

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Here is one way. Itab2 should be the same structure as itab1.

Loop at itab1.
   itab2 = itab1.
   collect itab2.
endloop.

Regards,

Rich Heilman

0 Kudos

but friends,

i have two questions:

1)after using collect statement,

will there be redundant entries like,

john

john

john

or only one john

2) if in place on name there is any numeric field like company code

will this collect statement add up the numeric company codes too. which should not happen.

thanks again.

0 Kudos

Hi Saritha,

1 - There will be no JOHN multiple times. It will just add numeric values which has the same key (All character fields).

2 - Company code are always numeric, but if you see the data type attached it is BUKRS which is of type character 4. So no need to worry

Reward points if useful.

Regards,

Atish

Former Member
0 Kudos

when any key fields(genrally fields which are of C,N,D,T,X datatypes are by default assign to the key fields of itab) of itab is repeating then the non key fields (like I,P) is getting added. so as per your requirement check the key fields are belongs to that data type or not.

regards

shiba dutta