2014 Sep 23 10:35 AM
Hello ABAPers
while debugging t_vbrk[ ] contains 98 rows and t_vbrp contains 33 rows still this loop is going infinite.any idea?
*==============================================
loop at t_vbrk.
if t_vbrk-fkart = 'ZRE'.
loop at t_vbrp .
if t_vbrk-vbeln eq t_vbrp-vbeln .
t_vbrp-ntgew = t_vbrp-ntgew * ( -1 ).
t_vbrp-netwr = t_vbrp-netwr * ( -1 ) .
APPEND T_VBRP.
endif.
endloop. " LOOP AT T_VBRP.
endif.
endloop.
*==============================================
thanks
2014 Sep 23 10:52 AM
Hi
As the guys have written above you're APPENDing a new record in T_VBRP, I suppone you want to change a value, so you should use MODIFY:
loop at t_vbrk.
if t_vbrk-fkart = 'ZRE'.
loop at t_vbrp .
if t_vbrk-vbeln eq t_vbrp-vbeln .
t_vbrp-ntgew = t_vbrp-ntgew * ( -1 ).
t_vbrp-netwr = t_vbrp-netwr * ( -1 ) .
APPEND T_VBRP.
MODIFY T_VBRP.
endif.
endloop. " LOOP AT T_VBRP.
endif.
endloop.
For the performance, you should use WHERE condition instead of IF into the LOOP:
loop at t_vbrk WHERE FKART = 'ZRE'.
if t_vbrk-fkart = 'ZRE'.
loop at t_vbrp WHERE VBELN = T_VBRK-VBELN.
if t_vbrk-vbeln eq t_vbrp-vbeln .
t_vbrp-ntgew = t_vbrp-ntgew * ( -1 ).
t_vbrp-netwr = t_vbrp-netwr * ( -1 ) .
APPEND T_VBRP.
MODIFY T_VBRP.
endif.
endloop. " LOOP AT T_VBRP.
endif.
endloop.
Max
2014 Sep 23 10:41 AM
Hi Faizur,
Add where condition to loop it will reduce some iteration.
YOu can also append the records into some temp internanal table.If you want to modify the T_VBRP use modify statement.
The belwo code will resolve your issue.
*==============================================
loop at t_vbrk.
if t_vbrk-fkart = 'ZRE'.
loop at t_vbrp where vbeln = t_vbrp-vbeln .
t_vbrp-ntgew = t_vbrp-ntgew * ( -1 ).
t_vbrp-netwr = t_vbrp-netwr * ( -1 ) .
MODIFY T_VBRP INDEX SY-TABIX TRANSPORTING ntgew netwr.
endloop. " LOOP AT T_VBRP.
endif.
endloop.
*==============================================
Regards,
Pravin
2014 Sep 23 10:42 AM
Hi,
I guess you are appending t_vbrp again inside t_vbrp Loop which can be the issue.
Rgeards,
K.S.
2014 Sep 23 10:46 AM
Hi,
AS KS pointed you are appending T_vbrp again and again which is causing loop to be end less, as each pass a new record is appended in same table.
2014 Sep 23 10:52 AM
Hi
As the guys have written above you're APPENDing a new record in T_VBRP, I suppone you want to change a value, so you should use MODIFY:
loop at t_vbrk.
if t_vbrk-fkart = 'ZRE'.
loop at t_vbrp .
if t_vbrk-vbeln eq t_vbrp-vbeln .
t_vbrp-ntgew = t_vbrp-ntgew * ( -1 ).
t_vbrp-netwr = t_vbrp-netwr * ( -1 ) .
APPEND T_VBRP.
MODIFY T_VBRP.
endif.
endloop. " LOOP AT T_VBRP.
endif.
endloop.
For the performance, you should use WHERE condition instead of IF into the LOOP:
loop at t_vbrk WHERE FKART = 'ZRE'.
if t_vbrk-fkart = 'ZRE'.
loop at t_vbrp WHERE VBELN = T_VBRK-VBELN.
if t_vbrk-vbeln eq t_vbrp-vbeln .
t_vbrp-ntgew = t_vbrp-ntgew * ( -1 ).
t_vbrp-netwr = t_vbrp-netwr * ( -1 ) .
APPEND T_VBRP.
MODIFY T_VBRP.
endif.
endloop. " LOOP AT T_VBRP.
endif.
endloop.
Max