Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How do i stop a Do Varrying Loop if no condition met?

Wil_Wilstroth
Active Participant
0 Kudos

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

William Wilstroth
1 ACCEPTED SOLUTION

former_member186741
Active Contributor
0 Kudos

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?

7 REPLIES 7

former_member223537
Active Contributor
0 Kudos

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

former_member186741
Active Contributor
0 Kudos

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?

0 Kudos

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

William Wilstroth

0 Kudos

hi

i dont know why are using do varying here.may i know what are you trying to achieve??

Cheers,

Abdul Hakim

0 Kudos

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.

0 Kudos

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.

former_member223537
Active Contributor
0 Kudos

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