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: 

Is there any direct syntax for summing two values

Former Member
0 Kudos

Friends,

I just have a problem of summing up two or more similar product_id 's quantities.

for ex: assume an Internal Table IT_PRODUCT. consider it has two fields one is PRODUCT_ID ( Primary key in Database ) and the other field is QUANTITY.

IT_PRODUCT.

________________________________

PRODUCT_ID QUANTITY

________________________________

I1001SA101 10

I1001SA101 20

________________________________

my desired output is to sum up the similar product_id' s of the internal table and to have only one summed record in the internal Table.

IT_PRODUCT

________________________________

PRODUCT_ID QUANTITY

________________________________

I1001SA101 30

________________________________

Is there any direct syntax to do the same or suggest me some more methods.

Pradeep.

6 REPLIES 6

Former Member
0 Kudos

Use COLLECT statement..

Check this code...

DATA : BEGIN OF itab OCCURS 0,

matnr LIKE ekpo-matnr,

menge LIKE ekpo-menge,

END OF itab.

DATA : itab2 LIKE itab OCCURS 50 WITH HEADER LINE.

SELECT matnr menge INTO CORRESPONDING FIELDS OF

TABLE itab FROM ekpo UP TO 20 ROWS.

LOOP AT itab.

COLLECT itab INTO itab2.

ENDLOOP.

Message was edited by:

Perez C

former_member188827
Active Contributor
0 Kudos

use

sum.

former_member386202
Active Contributor
0 Kudos

Hi,

Sort ur internal table with product_id and use COLLECT statement to add the quantity.

Ex.

loop at IT_PRODUCT.

Collect it_product to it_product1.

Endloop.

Reward Points

Regards,

Prashant

kesavadas_thekkillath
Active Contributor
0 Kudos

if these 2 fields are directly fetched from table then

select producti_d sum ( qty )..........group by product_id.

reward if usefull

Former Member
0 Kudos

Hi Pradeep,

use either Collect or Sum for ur Query.

Reward Points if useful.

Regards,

Shilpi