‎2008 Oct 28 5:51 AM
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.
‎2008 Oct 28 6:18 AM
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
‎2008 Oct 28 5:53 AM
‎2008 Oct 28 6:12 AM
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.
‎2008 Oct 28 6:18 AM
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
‎2008 Oct 28 8:29 AM
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