09-26-2006 2:45 AM
Hi all,
what is the best method to stop a loop in a DO VARYING from continuous looping (and getting an error dump)?
thanks
Regards,
William Wilstroth
09-26-2006 3:38 AM
pease give more details, if you post your code people will be able to come up with better examples.......
what sort of dump are you getting?
09-26-2006 2:52 AM
Hi,
You should put a condition which would be satisfied atleast once. Else you can set a flag.
DESCRIBE TABLE ITAB LINES l_lines.
DO VARYING ITAB-SRNO NEXT ITAB-PRNO.
IF ITAB-SRNO = '10'.
EXIT.
ENDIF.
<b>IF sy-tabix = l_lines.
EXIT.
ENDIF.</b>
ENDDO.
i.e. First get the total number of records in the internal table. If the processsing inside DO has already processed the total number of records, then EXIT.
Best regards,
Prashant
PS : Please reward all helpful answers
09-26-2006 3:38 AM
pease give more details, if you post your code people will be able to come up with better examples.......
what sort of dump are you getting?
09-26-2006 4:15 AM
For example,
Data : begin of t_dat occurs 0,
owner(020) type c,
property01(020) type c,
property02(020) type c,
property03(020) type c,
property04(020) type c,
end of t_dat.
Data : g_pro like t_dat-property01.
t_dat-owner = 'James Bond'.
t_dat-property01 = 'Bungalow'.
t_dat-property02 = 'Double Storey'.
Append t_dat.
Loop at t_dat.
do varying g_pro from t_dat-property01
next t_dat-property02.
if g_pro = 'Bungalow'.
write : / t_dat-owner, ' owns a ', g_pro.
exit.
endif.
enddo.
endloop.
So, if lets say the owner doesn't own any properties. Now when the do varying loops, how do i make it stop from causing error dump?
Thanks
Regards,
William Wilstroth
09-26-2006 4:25 AM
hi
i dont know why are using do varying here.may i know what are you trying to achieve??
Cheers,
Abdul Hakim
09-26-2006 4:49 AM
OK, in this case I'd code it like this:
do <b>4 times</b> varying g_pro from t_dat-property01
next t_dat-property02.
Then it will only try to operate on the 4 property fields.
09-26-2006 5:11 AM
try this...
Loop at t_dat.
do varying g_pro from t_dat-property01
next t_dat-property02.
if g_pro = 'Bungalow'.
write : / t_dat-owner, ' owns a ', g_pro.
exit.
<b>else if g_pro is initial.
exit.</b>
endif.
enddo.
endloop.
09-26-2006 5:06 AM
Hi,
Data : begin of t_dat occurs 0,
owner(020) type c,
property01(020) type c,
property02(020) type c,
property03(020) type c,
property04(020) type c,
end of t_dat.
Data : g_pro like t_dat-property01.
t_dat-owner = 'James Bond'.
t_dat-property01 = 'Bungalow'.
t_dat-property02 = 'Double Storey'.
Append t_dat.
Loop at t_dat.
<b>if t_dat-property01 eq 'Bungalow'.
write : / t_dat-owner, ' owns a ', t_dat-property01.
exit.
elseif t_dat-property02 eq 'Bungalow'.
write : / t_dat-owner, ' owns a ', t_dat-property02.
exit.
elseif t_dat-property03 eq 'Bungalow'.
write : / t_dat-owner, ' owns a ', t_dat-property03.
exit.
elseif t_dat-property04 eq 'Bungalow'.
write : / t_dat-owner, ' owns a ', t_dat-property04.
exit.
endif.</b>
enddo.
endloop.
Best regards,
Prashant
PS : Please reward all helpful answers