‎2008 May 06 4:24 AM
Hi Experts,
i have some confution in below code:
here am trying to calculate Actual Billing and Planned Revenue. but here for each value am looping it_final table inside the main loop.
but the prob is if i loop it_final for one value it is giving value, but if i try to loop 2 times for 2 values, it is not giving first value also.
i.e if i comment loop for Planned Revenue then Actual Billing is displaying, if i try for 2 values, then its giving zeros for 2 values.
so could anyone check is there any mistake i did.
CLEAR: it_prps, it_final, wa_final, wa_it_prps.
LOOP AT it_prps.
CASE month.
WHEN '08'.
ACTUAL BILLING
LOOP AT it_final INTO wa_final
WHERE posid = it_prps-posid
AND wrttp = c_04
AND beltp = c_02
AND versn = c_0
AND ( vorga = c_coin OR vorga = c_rku2 ).
CLEAR act_billing.
IF sy-subrc IS INITIAL.
MOVE wa_final-wlp08 TO t_act_billing.
act_billing = act_billing + t_act_billing.
ENDIF.
CLEAR: it_prps, it_final.
ENDLOOP.
*************PLANNED REVENUE
LOOP AT it_final INTO wa_final
WHERE posid = it_prps-posid
AND wrttp = c_01
AND beltp = c_02
AND versn = c_0
AND ( vorga = c_sdor OR vorga = c_rkp5 ).
CLEAR plan_rev.
IF sy-subrc IS INITIAL.
MOVE wa_final-wlp08 TO t_plan_rev.
plan_rev = plan_rev + t_plan_rev.
ENDIF.
CLEAR: it_prps, it_final.
ENDLOOP.
ENDCASE.
ENDLOOP.
WRITE:/10 'Actual Billing is',act_billing.
WRITE:/20 'Actual Cost is........', actu_cost.
Thanks in advace,
sudharsan.
‎2008 May 06 4:36 AM
hi,
CLEAR act_billing.
IF sy-subrc IS INITIAL.
MOVE wa_final-wlp08 TO t_act_billing.
act_billing = act_billing + t_act_billing.
ENDIF.
CLEAR: it_prps, it_final.
ENDLOOP.
your problem comes from here
CLEAR: it_prps, it_finalyou are clearing the header line of it_prps wherein it is used as a condition for the 2nd loop.
regards,
Peter
‎2008 May 06 4:53 AM
Hi,
as peter said dont clear the internal table clear the work area only.
Regards
Sandipan
‎2008 May 06 5:10 AM
No Friends, if i clear work area also it is not giving values, if i try for 2 values.
please check is there any other reason?
Thanks in Advance,
sudharsan.
‎2008 May 06 5:12 AM
Hi SUDHARSAN RAO
U r clearing the headers and tables. So u cannot use the values on the nested loops as u have cleared the values. There wont be anything in the workare ur using in where clause.
Please see the below comments that I kept.
LOOP AT it_prps.
ACTUAL BILLING
LOOP AT it_final INTO wa_final
WHERE posid = it_prps-posid
AND wrttp = c_04
AND beltp = c_02
AND versn = c_0
AND ( vorga = c_coin OR vorga = c_rku2 ).
CLEAR act_billing.
IF sy-subrc IS INITIAL.
MOVE wa_final-wlp08 TO t_act_billing.
act_billing = act_billing + t_act_billing.
ENDIF.
*******************************************
CLEAR: it_prps, it_final.
Here IT_FINAL is cleared by u... should not be cleared
********************************************
ENDLOOP.
*************PLANNED REVENUE
LOOP AT it_final INTO wa_final
WHERE posid = it_prps-posid
AND wrttp = c_01
AND beltp = c_02
AND versn = c_0
AND ( vorga = c_sdor OR vorga = c_rkp5 ).
CLEAR plan_rev.
IF sy-subrc IS INITIAL.
MOVE wa_final-wlp08 TO t_plan_rev.
plan_rev = plan_rev + t_plan_rev.
ENDIF.
Again ur clearing both tables.
CLEAR: it_prps, it_final.
********************************
ENDLOOP.
ENDCASE.
ENDLOOP.
WRITE:/10 'Actual Billing is',act_billing.
WRITE:/20 'Actual Cost is........', actu_cost.
‎2008 May 06 6:17 AM
hi sudharsan,
replace this code
CLEAR: it_prps, it_final.with this
append wa_final to it_final.
clear wa_final.
you are not appending the data to the internal table that is why only one record is being displayed.
regards,
Peter
‎2008 May 06 8:03 AM
Hi Peter,
how to append wa_final TO it_final.
actually we are getting values from it_final into wa_final while looping.
btu i tried like u also, eventhrough not working.
Rgds,
sudharsan.
‎2008 May 06 8:15 AM
Hi,
I see that you are clearing the variable ACT_BILLING inside the loop (LOOP at IT_FINAL).
That is the variable which holds the total and you are clearing inside the loop. that is the reason when there are multiple records it is not working fine.
Remove that clear statement. similar case for PLAN_REV.
These variables can be cleared before the loop actually begins.
Thanks and Regards,
Lakshmi.
‎2008 May 06 8:30 AM
i agree with Santhanalakshmi.
remove this lines.
CLEAR act_billing.
CLEAR plan_rev.
another reason for this is that your are displaying actu_cost here
WRITE:/20 'Actual Cost is........', actu_cost.
wherein you are using plan_rev.