2007 Sep 06 2:44 PM
i need to read a table and sum the quantity field until a reason code changes. how do I go about doing this?
2007 Sep 06 2:58 PM
You can refer to the following code for this.
LOOP AT itab INTO wa.
AT NEW region_id.
CLEAR wa_device.
ENDAT.
ENDLOOP.
Also you can use AT END OF construct similarly.
Hope this will help you.
~ Ramanath.
2007 Sep 06 2:47 PM
sort itab by reasoncode.
Loop at itab.
quantiy = quanity + itab-quantity.
at end of reasoncode.
jtab-reasoncode = itab-reasoncodee.
jtab-sum = quantity.
append jtab.
clear quantity.
endat
endloop.
or
sort itab by reasoncode.
loop at itab.
at end of reasoncode.
sum.
jtab = itab.
append jtab.
endat.
endloop.
or
let us say itab and jtab are two tables and you want to loop through itab and read jtab for reasoncodes.
if jtab has only one entry for each entry in itab then use read else use loop.
loop at itab.
loop at jtab where reasoncode = itab-reasoncode.
quantiy = quantiy + jtab-quanity.
endloop.
endloop.
or
loop at itab.
read table jtab with key reasoncode = itab-reasoncode.
if sy-subrc eq 0.
endif
endloop.
2007 Sep 06 2:51 PM
I am actually loop at a differnt table and reading another like this
loop at ITAB.
read table b
2007 Sep 06 2:53 PM
let us say itab and jtab are two tables and you want to loop through itab and read jtab for reasoncodes.
if jtab has only one entry for each entry in itab then use read else use loop.
loop at itab.
loop at jtab where reasoncode = itab-reasoncode.
quantiy = quantiy + jtab-quanity.
endloop.
endloop.
or
loop at itab.
read table jtab with key reasoncode = itab-reasoncode.
if sy-subrc eq 0.
endif
endloop.
2007 Sep 06 2:48 PM
HI,
Code like this:
loop itab1 into wa_itab1.
read table itab2 into wa_itab2 with key field2 = wa_itab1-field1.
if sy-subrc eq 0.
do the changes whatever you want.
endif.
endloop.
regards
Kannaiah
2007 Sep 06 2:49 PM
Hi,
You can use AT NEW contruct inside the loop for this purpose.
Inside AT NEW reset the value of quantity else add the quantity into the variable.
Hope this will help you.
~ Ramanath.
2007 Sep 06 2:54 PM
2007 Sep 06 2:58 PM
You can refer to the following code for this.
LOOP AT itab INTO wa.
AT NEW region_id.
CLEAR wa_device.
ENDAT.
ENDLOOP.
Also you can use AT END OF construct similarly.
Hope this will help you.
~ Ramanath.