2014 Oct 20 10:21 AM
Hi all,
I have an issue in a report which I would like to share with everyone. I am not quite sure why the error is occuring and I cant get the desired output. I have provided the screenshots along with my code so that the issue is clear to all.
I have a custom database table ZWM_IN_OR_RIG as shown.
On passing some parameters and executing, I get the following output:
Now I have sorted the field LOT NUMBER by descending order as per my requirement.
Also the fields ARQTY and DIDQTY must be added based on the indicator field IND. For a new Lot number LOTNO, if IND is "IN" then a summation of ARQTY needs to be done for that lot number. Similarly, if IND is "OUT" then a summation of DIDQTY needs to be done for that lot number. The difference of the totals of these 2 fields is REMQTY. Repeated lot numbers must be accumulated in one single row. Below is my code and my issues:
My issues are:
1) On debugging, I found out that, when 'IND' is OUT, the TOT_DIDQTY isnt getting added The entire addition part is getting bypassed, i.e. its jumping from line 87 to line 94 !! But values are getting populated but the addition isnt taking place.
2) After a few records, when IND is 'IN', the collect statement isnt working, whereas its supposed to add the value 100 to the previous value 1000 (as per the output of the database table). The report's incorrect output is below:
So am I using the COLLECT statement incorrectly? Please help.
Regards.
Manish.
2014 Oct 20 3:17 PM
Create a separate local type with lot number as first field, create a table and work area for that.
Say
Types: begin of ty_new,
lotno type zlotno,
whcode type...
prcode type ...
....
end of ty_new.
data it_new type table of ty_new.
data wa_new type ty_new.
Once you get the data from custom table (After select) , fill the data in this table.
loop at it_zmv_in_or_rig into wa_zmv_in_or_rig.
move-corresponding wa_zmv_in_or_rig to wa_new.
apend wa_new to it_new.
clear : ....
endloop.
Now sort it_new based on lot number.
now.
data lv_qty type zarqty.
loop at it_new into wa_new.
"""move comman of the fields to wa_final.
if wa_new-ind = 'IN'.
lv_qty = lv_qty + wa_new-arqty.
elseif wa_new-ind = 'OUT'.
lv_qty = lv_qty - wa_new-didqty.
endif.
at end of lotno.
wa_final-remqty = lv_qty.
clear lv_qty.
append wa_final to it_final.
clear : wa_final.
endat.
clear wa_new.
endloop.
endloop.
Try it, it should work.
2014 Oct 20 10:30 AM
Hi Manish,
Please check documentation of COLLECT for more info,
Collect will add numeric values only when all char fields are same, in this case the indicator as well as date is changing so collect wont add values.
2014 Oct 20 12:30 PM
Hi,
Ok, I am removing the COLLECT statement. So how do I get my desired output now?
Regards.
Manish.
2014 Oct 20 12:33 PM
Use AT NEW or ON CHANGE OF as you are doing now and manually add the variables and append
2014 Oct 20 12:06 PM
Hi Manish,
You used collect inside on change of lotid, Hence whenever change in lot number that time only collect statement will executed( in your example 2 times), that each time indicator seems to be 'IN'.
Remove ONCHANGE of LOTNUMBER, directly Collect to IT FINAL internal table.
Then loop over IT FINAL with assigning to field symbol( to calculate difference) , the calculate the difference .
Thanks & Regards,
Arun
2014 Oct 20 1:35 PM
Hi Manish,
I think you have to Use
ON CHANGE OF LOT NO.
instead of ..
ON CHANGE OF WA_ZMW_IN_OR_RIG-LOT NO.
And Ensure that lotno is the first field of your internal table IT_ZMW_IN_OR_RIG.
Regards,
Shashikanth
2014 Oct 21 5:31 AM
Hi,
When u use only the field while using ON CHANGE OF, there will be an error. The work area has to be mentioned.
Regards.
Manish
2014 Oct 20 3:17 PM
Create a separate local type with lot number as first field, create a table and work area for that.
Say
Types: begin of ty_new,
lotno type zlotno,
whcode type...
prcode type ...
....
end of ty_new.
data it_new type table of ty_new.
data wa_new type ty_new.
Once you get the data from custom table (After select) , fill the data in this table.
loop at it_zmv_in_or_rig into wa_zmv_in_or_rig.
move-corresponding wa_zmv_in_or_rig to wa_new.
apend wa_new to it_new.
clear : ....
endloop.
Now sort it_new based on lot number.
now.
data lv_qty type zarqty.
loop at it_new into wa_new.
"""move comman of the fields to wa_final.
if wa_new-ind = 'IN'.
lv_qty = lv_qty + wa_new-arqty.
elseif wa_new-ind = 'OUT'.
lv_qty = lv_qty - wa_new-didqty.
endif.
at end of lotno.
wa_final-remqty = lv_qty.
clear lv_qty.
append wa_final to it_final.
clear : wa_final.
endat.
clear wa_new.
endloop.
endloop.
Try it, it should work.
2014 Oct 21 6:24 AM
Hi,
Perfect solution . Thanks a lot . A very simple logic. Wish I thought a little harder!
Regards.
Manish.