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

Simple loop - while & do

Former Member
0 Likes
1,087

Hi,

I wrote the code as below, when i was debugging everthing is working fine but when i was executing directly, the cursor is not coming out. can you please suggest me the alternative.

code is

data: gv_delay type i value 10,

gv_time_end type sy-uzeit.

gv_time_end = sy-uzeit + gv_delay.

  • while sy-uzeit le gv_time_end.

  • write: /10 sy-uzeit.

  • endwhile.

do.

if sy-uzeit > gv_time_end.

exit.

endif.

write: /20 sy-uzeit.

enddo.

write: /10 'Something'.

regards,

Jaya

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,048

Try:


do.
  get time
  if sy-uzeit > gv_time_end.
    exit.
  endif.
  write: /20 sy-uzeit.
enddo.

Rob

8 REPLIES 8
Read only

Former Member
0 Likes
1,049

Try:


do.
  get time
  if sy-uzeit > gv_time_end.
    exit.
  endif.
  write: /20 sy-uzeit.
enddo.

Rob

Read only

0 Likes
1,048

Hi Rob,

Its really wonderful, i will surely reward points. But can you please let me know what exactly the problem in my code & what is happening when we use <b>get time.</b>

Thanks

jaya

Read only

0 Likes
1,048

Get Time is basically updating the following fields:

sy-datlo, sy-datum, sy-timlo, sy-uzeit, and sy-zonlo to the current value.

Without the command Get Time you are using the same value for sy-uzeit for every iteration through the loop.

Message was edited by:

Davis

Read only

0 Likes
1,048

You would think that sy-uzeit would always contain the current time, but it doesn't. According to the documentation, GET TIME:


Sets the system field SY-UZEIT to the current time and resets SY-DATUM. Also refreshes the SY fields for the local time zone, i.e. SY-TIMLO, SY-DATLO and SY-ZONLO. 

Rob

Read only

0 Likes
1,048

Rob, when I first opened this thread I assumed that it did contain the current time. I was quite surprised to find out (through debug) that it didn't. This could be valuable information in the future.

Regards,

Davis

Read only

0 Likes
1,048

The question is why it worked in debug mode at all.

Things like COMMITs will also reset sy-uzeit and I guess also executing a command in the debugger.

Rob

Read only

Former Member
0 Likes
1,048

You need to get the time inside your loop. Otherwise you are working with the same time and will create an infinite loop.

Regards,

Davis

EDIT: Sorry, I did not see that Rob already responded with the correct code.

Message was edited by:

Davis

Read only

0 Likes
1,048

Hi Rob & David,

Both are really unsful to me so i rewarded both of you...

regards

jaya