Application Development and Automation 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: 
Read only

how to exit from loop after 3 time

former_member459142
Participant
0 Likes
1,559

hi

how to exit from loop after 3 time

loop at itab.

<exit after 3 time>

endloop.

thanks

hi

how to exit from loop after 3 time

loop at itab.

<exit after 3 time>

endloop.

thanks

9 REPLIES 9
Read only

Former Member
0 Likes
1,430

loop at itab.

if sy-tabix >= 3.

exit.

endif.

endloop.

Edited by: Kalyan Chakravarthi on Mar 16, 2009 12:08 PM

Read only

Former Member
0 Likes
1,430

Hi,

sy-index is a system filed

if sy-index = 3 then

exit from the loop

Thanks

Ramakrishna Pathi

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
1,430

Hi,

Use:


loop at itab.
  if sy-tabix = 3.
    exit. "to exit for loop
    "continue. "to go to next loop pass
  endif.
endloop.

Regards,

Tarun

Read only

Former Member
0 Likes
1,430

try this...


data: count type i value 0.

loop at itab.

count  = count + 1.
if count = 3.
   exit. "to exit for loop
    "continue. "to go to next loop pass

endif.

endloop.

Edited by: Arunima Rudra on Mar 16, 2009 4:39 PM

Read only

Former Member
0 Likes
1,430

Hi Gupta,

loop at itab.

if sy-tabix EQ 3.

EXIT.

endloop.

I think this will workout check it once.

Thanks & Regards,

Kaza

Read only

Former Member
0 Likes
1,430

Hi ,

caheck this code

Loop at t_itab.
 
if sy-tabix gt 3.
exit.
endif.
 
endloop.

thanks and regrds

Durga.K

Read only

Former Member
0 Likes
1,430

Hi,

You can check the value of SY_TABIX inside loop,

For Example:



Loop at itab.

if sy-tabix  = 3.

Exit.

endif.

Endloop.

Hope it helps

Regrds

Mansi

Read only

Former Member
0 Likes
1,430

Hi,

This is very simple...

data:counter type i value 0.

loop at itab.

counter = counter + 1.
if counter eq 3.
exit."this will take out of the loop at itab
endif.

endloop.

OR

rather than taking and loacal variable simply use sy-tabix value as expalined above can be a solution.

Pooja

Edited by: Pooja Gupta on Mar 16, 2009 12:18 PM

Read only

former_member459142
Participant
0 Likes
1,430

thanks