Application Development and Automation 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: 
Read only

Summation

Former Member
0 Likes
765

Hi Friends,

I have data in internal table,

ex:

matnr lgort dmbtr sum

10 xyz 100

10 xyz 500

20 pqr 200

20 pqr 400

30 abc 000

40 abc 200

I am doing the sum for the field dmbtr based on material number and storing the value under sum field.

matnr lgort dmbtr sum

10 xyz 100

10 xyz 500 600

20 pqr 200

20 pqr 400 600

30 abc 000 000

40 abc 200 200

Now I want only those records with the field sum,

Can any one tell me how to do this.

Thanx in advance,

Venu

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
737

Hi

Perhaps the easier way is to use another table for the sum:

DATA: ITAB_SUM LIKE STANDARD TABLE OF ITAB WITH HEADER LINE.

LOOP AT ITAB.

COLLECT ITAB TO ITAB_SUM.

DELETE ITAB.

ENDLOOP.

ITAB[] = ITAB_SUM[].

Max

6 REPLIES 6
Read only

Former Member
0 Likes
738

Hi

Perhaps the easier way is to use another table for the sum:

DATA: ITAB_SUM LIKE STANDARD TABLE OF ITAB WITH HEADER LINE.

LOOP AT ITAB.

COLLECT ITAB TO ITAB_SUM.

DELETE ITAB.

ENDLOOP.

ITAB[] = ITAB_SUM[].

Max

Read only

Former Member
0 Likes
737

Loop at itab where sum is not initial.

endloop.

OR

delete itab where sum is initial.

Read only

Former Member
0 Likes
737

Hi Venu,

Create one more final internal table i_tab2 of type

I_tab1.(having all the details)

Loop at I_tab1 into wa_itab1.

Collect wa_itab1 into i_tab2.

I_tab2 will have all the sum values as per the matnr,Lgort.

Reward points if this helps.

Manish

Read only

Former Member
0 Likes
737

Hi,

It seems that You need the summation by Material and Storage Location as per the given example by You.

let us say data is in itab internal table. You can write the below logic.

sort itab by matnr lgort.

loop at itab.

at end of lgort.

sum.

itab-sum = itab-dmbtr.

modify itab index sy-tabix transporting sum.

endat.

endloop.

delete itab where sum = 0.

by this logic you will get summation of records by Material and Storage location.

Thanks,

sksingh

Read only

Former Member
0 Likes
737

Hi venu,

1. simple

2. a) Create one another internal table STAB

with only two fields, (keep field name same)

- matnr

- dmbtr

b) suppose your original internal table is itab

c) LOOP at ITAB

MOVE-CORRESPONDING ITAB TO STAB.

COLLECT STAB.

ENDLOOP.

3. This STAB will have ONLY SUMS.

regards,

amit m.

Read only

Former Member
0 Likes
737

s d esay way is

DATA: ITAB_SUM LIKE STANDARD TABLE OF ITAB WITH HEADER LINE.

LOOP AT ITAB.

COLLECT ITAB TO ITAB_SUM.

ENDLOOP.

loop at ITAB_SUM.

print 3 fields.

endloop.

or...

for d existing code....

data: wa_itab type itab.

loop at itab.

wa_itab = itab.

at end of lgort.

print 4 ields in wa_itab.

endat.

endloop.

Ramesh.