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

Help for coming out from Loop...Endloop

Former Member
0 Likes
1,373

Dear All,

I have one internal table with 10000 records . I want to read a specific record with certain WHERE clause with logical operators.

Now my requirement is that as soon as that condition is satisfied , control should go to next line after Endloop BUT NOT to the next loop pass so that it will not read remaining entries.

Suggestions are most welcome.

Thanks...........

12 REPLIES 12
Read only

Former Member
0 Likes
1,316

Hi,

Use Command: EXIT.

Thanks.

Read only

0 Likes
1,316

EXIT. command should work.

Read only

Former Member
0 Likes
1,316

Try this..

Loop at itab.

if <Condition>.

EXIT.

endif.

Endloop.

Read only

Former Member
0 Likes
1,316

EXIT

Read only

Former Member
0 Likes
1,316

Hi,

Using EXIT we can come out of the loop.

By using CONTINUE we can come out of the current iteration.

Regards,

Surya kiran

Read only

Former Member
0 Likes
1,316

hi;

there are 2 ways

like

1.

loop where condition

endloop.

2.

loop

if condition

exit.

endif.

endloop.

Regards

Shashi

Read only

Former Member
0 Likes
1,316

Hi,

Use exit command.

Loop at itab into wa.

if wa-field = 'CONDITION'.

EXIT.

endif.

endloop.

Cheers,

Rudhir

Read only

Former Member
0 Likes
1,316

If you are looking to read specific record why do you require LOOP .. WHERE .

Please use READ TABLE WITH KEY... which will read only required record and you are process further processing.

This will improve performance over LOOP ...

Edited by: Sunil Sawaikar on Mar 12, 2009 12:42 PM

Read only

Former Member
0 Likes
1,316

Hi,

Data is huge so make use off field symbol. Follow the below logic.

Field-symbol : <fs_wa_tab> type wa_tab.

Loop at i_tab assigning <fs_wa_tab>.

if (condition)

..........................

..........................

exit.

endif.

endloop.

Thanks,

Asit Purbey.

Read only

faisalatsap
Active Contributor
0 Likes
1,316

Hi,

You can use

RETURN

Kind Regards,

Faisal

Read only

Former Member
0 Likes
1,316

hi after select stmt write this.

select * _______

if sy-dbcnt eq 0.

do this.

else.

go to next line code here.

endif.

Read only

Former Member
0 Likes
1,316

Hi,

if the conditions gives you a single record or you want to exit the loop as soon as atleast one record is read then make use of read statement instead of loop...endloop.

read table <tabname> into <workarea> with key <conditions>.
if sy-subrc = 0. " means the record is found... write the steps you have written after endloop if its found...
endif.

if the conditions gives you multiple records, then use loop and if you want to exit on certain condition...

then use loop....endloop.

loop at itab into wa  where conditions.
  if <condtition>.
       exit.
  endif.
endloop.

Regards,

Siddarth