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

LOOP PROCESSING

Former Member
0 Likes
836

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
Read only

Former Member
0 Likes
804

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

Regards,

Ravi

7 REPLIES 7
Read only

Former Member
0 Likes
805

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

Regards,

Ravi

Read only

0 Likes
804

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

Read only

0 Likes
804
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

Read only

Former Member
0 Likes
804

hi ,

try this

data count type i value 0.

loop at i tab into wa.

count = count + 1.

if count = 10.

exit.

endif.

endloop.

Read only

Former Member
0 Likes
804

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

Read only

Former Member
0 Likes
804

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

Read only

sourabhshah
Product and Topic Expert
Product and Topic Expert
0 Likes
804

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.