‎2008 May 06 2:38 PM
Hi Experts,
i ve problem in nested loop. my peace of code is below.
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.
CLEAR: wa_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.
PLANNED COST
LOOP AT it_final INTO wa_final
WHERE posid = it_prps-posid
AND wrttp = c_01
AND versn = c_0
AND beltp = c_1.
CLEAR plan_cost.
IF sy-subrc IS INITIAL.
MOVE wa_final-wlp08 TO t_plan_cost.
plan_cost = plan_cost + t_plan_cost.
ENDIF.
CLEAR: wa_final.
ENDLOOP.
ENDCASE.
ENDLOOP.
In the above code am trying to find 3values like Actual Billing, Planned Revenue and Planed cost.
Under the main loop Loop at it_prps. here am looping the table it_final 3times for finding 3values.
but the problem is if i comment for below 2 loops, then First loop is doing well. but if i open for 3 loops
now supose if First loop fails then control is come out of main loop( it_prps ), it is going to 2nd and 3rd loops. and its giving zero values.
Could anyone tell me where i gone rong, how control will come to 2nd loop if 1st loop fails.
Thanks in Advance,
sudharsan.
Edited by: SUDHARSAN RAO on May 6, 2008 3:39 PM
‎2008 May 06 3:19 PM
Number of issues with this code.
First.. how is it_final defined. With a header? or standard table of wa_final?
If like the 2nd (standard table of wa_final) then this line will clear the table. CLEAR: it_prps, it_final.
Other observations.
In each of your internal loops that have the pattern like this
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.
CLEAR: wa_final.
ENDLOOP.
Should be recoded to look like this
CLEAR act_billing. "<== Moved
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 ).
** IF sy-subrc IS INITIAL. " Don't Need this.. will only come in here if record found
MOVE wa_final-wlp08 TO t_act_billing.
act_billing = act_billing + t_act_billing.
** ENDIF. " Matches the IF
** CLEAR: it_prps, it_final. " Shouldn't need this
** CLEAR: wa_final. " Shouldn't need this
ENDLOOP.
‎2008 May 06 3:07 PM
Hi.
I think you should a flag to check the process in each for loops.
thats all..
‎2008 May 06 3:19 PM
Number of issues with this code.
First.. how is it_final defined. With a header? or standard table of wa_final?
If like the 2nd (standard table of wa_final) then this line will clear the table. CLEAR: it_prps, it_final.
Other observations.
In each of your internal loops that have the pattern like this
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.
CLEAR: wa_final.
ENDLOOP.
Should be recoded to look like this
CLEAR act_billing. "<== Moved
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 ).
** IF sy-subrc IS INITIAL. " Don't Need this.. will only come in here if record found
MOVE wa_final-wlp08 TO t_act_billing.
act_billing = act_billing + t_act_billing.
** ENDIF. " Matches the IF
** CLEAR: it_prps, it_final. " Shouldn't need this
** CLEAR: wa_final. " Shouldn't need this
ENDLOOP.
‎2008 May 06 3:26 PM
Hi Sudarshan,
Check the below code....
LOOP AT it_prps.
CASE month.
WHEN '08'.
LOOP AT it_final INTO wa_final
posid = it_prps-posid.
IF wrttp = c_04
AND beltp = c_02
AND versn = c_0
AND ( vorga = c_coin OR vorga = c_rku2 ).
*Do the process for ACTUAL BILLING
ENDIF.
IF wrttp = c_01
AND beltp = c_02
AND versn = c_0
AND ( vorga = c_sdor OR vorga = c_rkp5 ).
*Do the process for PLANNED REVENUE
ENDIF.
IF wrttp = c_01
AND versn = c_0
AND beltp = c_1.
CLEAR plan_cost.
*Do the process for PLANNED COST
ENDIF.
CLEAR: it_prps, it_final.
CLEAR: wa_final.
ENDLOOP.
ENDCASE.
ENDLOOP.
Cheers,
Bujji