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

Do loop doesn't seem to be looping.

Former Member
0 Likes
721

Hi.

I incorporated a DO loop in a subroutine, but it doesn't seem to be working.

**********************************************************************

FORM VALIDATE_FILEPATH.

DO 10 TIMES.

SELECT AREA_A_FILE_MAND INTO MAND_CHECK FROM ZSCSDM_OF

WHERE OBJECT_ID = 'STUD' AND FILE_NUMBER = SY-INDEX.

ENDSELECT.

MESSAGE E002(ZMSGGARY) WITH SY-INDEX.

ENDDO.

ENDFORM.

**********************************************************************

The message will always return 1 (i.e. SY-INDEX is always = 1)

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
671

Hi,

MESSAGE E002(ZMSGGARY) WITH SY-INDEX.

this is stopping the process of do loop

put in a condition atleast..

like

DO 10 TIMES.

SELECT AREA_A_FILE_MAND INTO MAND_CHECK FROM ZSCSDM_OF

WHERE OBJECT_ID = 'STUD' AND FILE_NUMBER = SY-INDEX.

<b>so when ever it is failed this will give the message</b>

<b>if sy-subrc ne 0.

MESSAGE E002(ZMSGGARY) WITH SY-INDEX.

endif.</b>

ENDSELECT.

ENDDO.

regards,

Venkatesh

Hi.

I incorporated a DO loop in a subroutine, but it doesn't seem to be working.

**********************************************************************

FORM VALIDATE_FILEPATH.

DO 10 TIMES.

SELECT AREA_A_FILE_MAND INTO MAND_CHECK FROM ZSCSDM_OF

WHERE OBJECT_ID = 'STUD' AND FILE_NUMBER = SY-INDEX.

ENDSELECT.

MESSAGE E002(ZMSGGARY) WITH SY-INDEX.

ENDDO.

ENDFORM.

**********************************************************************

The message will always return 1 (i.e. SY-INDEX is always = 1)

Thanks

5 REPLIES 5
Read only

Former Member
0 Likes
672

Hi,

MESSAGE E002(ZMSGGARY) WITH SY-INDEX.

this is stopping the process of do loop

put in a condition atleast..

like

DO 10 TIMES.

SELECT AREA_A_FILE_MAND INTO MAND_CHECK FROM ZSCSDM_OF

WHERE OBJECT_ID = 'STUD' AND FILE_NUMBER = SY-INDEX.

<b>so when ever it is failed this will give the message</b>

<b>if sy-subrc ne 0.

MESSAGE E002(ZMSGGARY) WITH SY-INDEX.

endif.</b>

ENDSELECT.

ENDDO.

regards,

Venkatesh

Read only

Former Member
0 Likes
671

HI,

you are making the message for each loop.

for the first time it will go insdide...

then it will give error message

then it will come out of the do loop.

if you want the message every time and to continue the loop

you can make it success message ...

regards,

Venkatesh

Read only

Former Member
0 Likes
671

Hi,

do like this

SELECT AREA_A_FILE_MAND INTO table MAND_CHECK FROM ZSCSDM_OF
WHERE OBJECT_ID = 'STUD'.

loop at mand_check.
 if sy-index > 10.
  exit.
 else.
  MESSAGE E002(ZMSGGARY) WITH SY-INDEX.
 endif.
endloop.

<b>Reward for helpful answers</b>

Satish

Read only

Former Member
0 Likes
671

Hi,

change message type to S

MESSAGE S002(ZMSGGARY) WITH SY-INDEX.

Read only

Former Member
0 Likes
671

for looping through itab, we should use sy-tabix instead of sy-index. if i use sy-index, somehow it returns 0 instead of 1, 2....

loop at mand_check.

if sy-index > 10. ==> NO.

IF SY-TABIX > 10 ==> YES.