09-16-2008 9:32 AM
hi experts
i have a problem with my code:
SORT i_data by lifnr grund.
loop for summing quantity for each vendor and reason
for movment:
LOOP at i_data INTO wa_data.
if i_data-shkzg = 'H'.
i_data-erfmg = i_data-erfmg * -1.
modify i_data.
ENDIF.
at END OF grund.
SUM.
flag = 1.
outtab-erfmg = wa_data-erfmg.
ENDAT.
if flag = 1.
outtab-lifnr = wa_data-lifnr.
outtab-name1 = wa_data-name1.
outtab-kvgr1 = wa_data-kvgr1.
outtab-bezei = wa_data-bezei.
outtab-stras = wa_data-stras.
outtab-ort01 = wa_data-ort01.
outtab-telef1 = wa_data-telf1.
outtab-kunnr = wa_data-kunnr.
outtab-grund = wa_data-grund.
outtab-preis = wa_data-preis.
outtab-bwaer = wa_data-bwaer.
outtab-peinh = wa_data-peinh.
outtab-bprme = wa_data-bprme.
APPEND outtab.
flag = 0.
endif.
ENDLOOP.
the statement at end of grund works only in the first time i.e.,
when i have for example three first rows with the same grund it takes the third row but in
the next three rows with the same grund it takes the first instead of third
what's the problem?
thanks
amit
09-16-2008 9:41 AM
probably they have a different value in LIFNR
when you do "AT END OF grund." the statement considers all fields up to the field "grund"
so if you want to break on this field only, you have to put it in front !
09-16-2008 9:41 AM
probably they have a different value in LIFNR
when you do "AT END OF grund." the statement considers all fields up to the field "grund"
so if you want to break on this field only, you have to put it in front !
09-16-2008 9:42 AM
Hi Amit,
It is because your i_data may not have GRUND as first field.
Show us the structure of I_DATA table.
Suppose if GRUND is the third field of I_DATA, then even if the second field changes - AT END OF will be triggered.
Keep GRUND as the first field in that table structure.then it will work as you want now
Cheers,
Kothand
09-17-2008 9:21 AM
hi kothand
in continue to your reply, i want to sum all the rows in i_data with the same grund and lifnr
and to put the sum in other table how can i do this.
thanks
amit
09-16-2008 9:43 AM
In Your Internal Table
grund must be the First Field
Then and then only at End of grund
works
Regards,
Alpesh
09-16-2008 9:55 AM
Hi,
Use grund field as the first column of the internal table and apply the same logic.
Because at end of compi, the control breaks happens when the left field of compi changes.
09-17-2008 10:51 AM
Don't use AT END OF in the same LOOP as u r modifying the values it leads to inconsistency.
Finish this loop and sort the itab againg then use AT END OF statement it will give the correct results.