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: 

LOOP PROCESSING

Former Member
0 Kudos

HII FRNDS

CAN I RESTRICT A LOOP BEING PROCESED TO A LIMITED NO OF TIMES. IF YES THN HOW . I AM TRYIGN OUT WITH TABIX BUT ITS NOT WORKING CAN ANYBODY TELL ME ANY OTHER ALTERNATICES ..

THANX

ROHIT

1 ACCEPTED SOLUTION

Former Member
0 Kudos

You can have a counter, increment it manually and then exit depending on your condition.

Regards,

Ravi

7 REPLIES 7

Former Member
0 Kudos

You can have a counter, increment it manually and then exit depending on your condition.

Regards,

Ravi

0 Kudos

YA BUT HOW SHOULD I CATCH THE NO OF TIMES MY LOOP HAS BEEN PROCESSED ..

0 Kudos
DATA : COUNTER TYPE I.

LOOP AT ITAB.

Process the data 
 
 COUNTER = COUNTER + 1. " This will tell you how many times the loop has been processed.
 IF COUNTER = your number.
   exit.
 ENDIF.
ENDLOOP.

If your number is bigger the number of entries in the internal table, it will come out once it processes all the entries.

Regards,

Ravi

Note - Please mark all the helpful answers

Former Member
0 Kudos

hi ,

try this

data count type i value 0.

loop at i tab into wa.

count = count + 1.

if count = 10.

exit.

endif.

endloop.

Former Member
0 Kudos

Hi Rohit ,

You can very well do it. Here is a sample code for the same

Data : Begin of it_1 occurs 0 ,
         test type i,
       End of it_1.
 Data : v_temp type i.
start-of-selection.
clear v_temp.
while v_temp < 10.

v_temp = v_temp + 1.
it_1-test = v_temp.
append it_1.
endwhile.
clear v_temp.
loop at it_1.
  if sy-tabix < 5.
    write it_1-test.
  else.
   exit.
  endif.
endloop.

Regards

Arun

Former Member
0 Kudos

you can use

do n times.

enddo.

where n is your defined number.

or <b>loop at itab</b>.

if sy-tabix = n.

exit.

endif.

endloop.

or data : counter type i.

loop.

counter = counter + 1.

if counter = n.

exit.

endif.

endloop.

regards

shiba dutta

sourabhshah
Advisor
Advisor
0 Kudos

Hi,

This is executable sample code .

Data: lv_tabix type sy-tabix,

itab type table of spfli,

wa type spfli.

Select * from spfli into table itab.

Check sy-subrc = 0.

Loop at itab into wa.

lv_tabix = sy-tabix.

if lv_tabix > 4.

exit.

endif.

write lv_tabix.

Endloop.