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: 

Summing value in Internal Table

Former Member
0 Kudos

Hi Abapers,

I have some problem during manipulating the internal table:

The scenario is like this

I have one internal Table:

Material Curr PO Quantity

A EUR 10

A EUR 15

A GBP 20

A GBP 10

B USD 10

Now I have to Sum the POQty and put this in other field Sum of Internal Table on the basis of grouping materail as well as Curr.

For Material A and Curr EUR, i should get sum of PO Qty 25 and

for material A and Curr GBP, i shld get sum of PO Qty 30 and

For B - USD, i shld get 10 in Sum field.

How to do this in ABAP Code?

Please solve my this issue.

Regards,

Rahul Sinha

4 REPLIES 4

Former Member
0 Kudos

Hi Rahul,

This is quite simple. We can use COLLECT and it will sum automatically.

1. Declare another internal table, eg. STAB

with three fields only

Material

Curr

PO Quantity

2. Not loop at your original internal table say ITAB, and write like this.



loop at itab.

move-corresponding itab to stab.

COLLECT STAB.

Endloop.


I assume STAB and ITAB have same field names, hence i have written move-corresponding.

Based upon PO and CURR combination, (ie. DISTINCT combination of alphanumeric fields in STAB),

collect will do the sum automatically.

regards,

amit m.

Former Member
0 Kudos

Hello Rahul ,

Solution 1 :-Using own logic

Just use an on change of at the PO field ....

On change of (PO field) , sum the quantity and put it ...

Solution 2:Using COLLECT statement

I think there is no need of on change ..you could use the COLLECT keyword

Comradely,

K.Sibi

Edited by: sibi k kanagaraj on Dec 22, 2009 2:20 PM

Edited by: sibi k kanagaraj on Dec 22, 2009 2:22 PM

Former Member
0 Kudos

Hi Rahul,

While Appending the data to internal table use COLLECT statement instead of APPEND..

COLLECT statement will add the quantity fields if the other fields are same ie, material and currency fields in your case.

So for your case, internal table will have data when you use COLLECT statement

A EUR 25

A GBP 30

B USD 10

Former Member
0 Kudos

Please do not ask or answer basic questions - thread locked.

Rob