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

sum data in table

Former Member
0 Likes
546

Hi,

I want to loop at table and sum all the amount by the field LGART.

lgart is not the first field on the table so AT END AT NEW wont help here.

is there any idea about how to do it.??

if the lgart was first field i would do ;


LOOP AT  i_zl INTO wa_zl.
    MOVE wa_zl TO l_wa_zl.
    AT NEW lgart.
      CLEAR: sum_anzhl.
    ENDAT.
    sum_anzhl = sum_anzhl + l_wa_zl-anzhl.
    AT END OF lgart.
      wa_zl-anzhl = sum_anzhl.
      MODIFY i_zl FROM wa_zl TRANSPORTING anzhl
      WHERE lgart = l_wa_zl-lgart.
    ENDAT.
  ENDLOOP.
  DELETE ADJACENT DUPLICATES FROM i_zl COMPARING lgart.

Thanks in advanced.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
511

Hi,

in order to bypass first loop make use of flag..

say for example

data : flag.

on change of.

if flag = 'X'. // for the first time flag is space so it does not enter ...

....

endif.

flag = 'X'.

endon.

Hope this is helpful...

Rgds.,

subash

4 REPLIES 4
Read only

Former Member
0 Likes
511

Hi Gil,

Use ON CHANGE OF<field>.

Read only

0 Likes
511

Thanks.

it's really solve the problem.

but in the first enter of the loop it's go to ON CHANGE OF

i's there something to bypass it like at new??

thanks.

Read only

Former Member
0 Likes
512

Hi,

in order to bypass first loop make use of flag..

say for example

data : flag.

on change of.

if flag = 'X'. // for the first time flag is space so it does not enter ...

....

endif.

flag = 'X'.

endon.

Hope this is helpful...

Rgds.,

subash

Read only

Former Member
0 Likes
511

HI,

use this.



Data: l_lgart_old type lgart,
         l_lgart_ney type lgart.

sort itab by lgart.

Loop at itab.
clear l_flag.
l_lgart_new = itab-lgart.

itab2-amt = itab2-amt + itab-amt. 

if l_lgart_old is not initial and l_lgart_old <> l_lgart_new.
 l_flag = 'X'
  append itab2.
  clear  itab2.

endif.

l_lgart_old = l_lgart_new.

at last.
if l_flag is initial.
append itab2.
endif.
endata.
Endloop.

Regards,

Jey