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

EXITING FROM LOOP

Former Member
0 Likes
719

if in a loop iam checkin a condition n if the condition satisfies then which is the best way to exit the loop.

7 REPLIES 7
Read only

Former Member
0 Likes
685

Hi

USE EXIT within the loop thats the best way to exit out of the loop.

Cheers

VJ

Read only

Former Member
0 Likes
685

Hi

After the condition satisfies,write EXIT or STOP.

Thanks

Read only

satykumar
Product and Topic Expert
Product and Topic Expert
0 Likes
685

Hi,

Use EXIT for the same

if sy-subrc = 0.

exit.

endif.

Regards,

Satyendra

Read only

Former Member
0 Likes
685

Hi Sushant,

Use EXIT in the LOOP after the condition .If u use STOP it will exit from the Program.

Try this example creating a Program by uncommending EXIT and STOP.

DATA: t_mara TYPE STANDARD TABLE OF mara.

DATA: w_mara TYPE mara,

sum TYPE i.

SELECT matnr mtart FROM mara INTO CORRESPONDING FIELDS OF TABLE t_mara

WHERE mtart EQ 'KMAT' OR mtart EQ 'FERT' OR mtart EQ 'LGUT'.

sum = 0.

IF sy-subrc EQ 0.

SORT t_mara BY mtart.

LOOP AT t_mara INTO w_mara.

IF w_mara-mtart EQ 'LGUT'.

sum = sum + 1.

  • EXIT.

*STOP.

ENDIF.

ENDLOOP.

ENDIF.

WRITE : sum.

Reward Points if useful.

Regards

Avi...

Read only

Former Member
0 Likes
685

Hi,

Use EXIT Statment inside loop, you are exiting from the loop.

If hleps plz reward points.

Regards

Bhupal Reddy

Read only

sreeramkumar_madisetty
Active Contributor
0 Likes
685

Hi

Use EXIT Statment within the loop, this can takes the control out of the loop if the condition satisfies.

Regards,

kumar

Read only

Former Member
0 Likes
685

Hi ,,

Exit is the best option , because if you use STOP control then goes to End-of-selection .

Thanks .