Application Development 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: 

Endless loop with WHILE ?

Former Member
0 Kudos

Hi Fox,

The bellow coding should terminate the function after a certain time in seconds (as input parameter) and displays the variable count. But it terminates at the end with the short dump since the count becomes an overflow. Thanks for you help.

Function xxxx

import: time_out type i.

DATA: c_syuzeit TYPE sy-uzeit,

count TYPE i.

c_syuzeit = sy-uzeit.

c_syuzeit = c_syuzeit + time_out.

WHILE c_syuzeit > sy-uzeit.

ADD 1 TO count.

ENDWHILE.

ENDFUNCTION xxx.

1 ACCEPTED SOLUTION

johndeconinck
Participant
0 Kudos

Hi,

Sy-uzeit will always contain the time the report has been launched (it will not change during runtime). To update this variable you can use the ABAP command "GET TIME".

Kind regards,

John.

20 REPLIES 20

former_member181995
Active Contributor
0 Kudos

use EXIT with certain condition in while endwhile.

JozsefSzikszai
Active Contributor
0 Kudos

what is the problem?

here: WHILE c_syuzeit > sy-uzeit.

ADD 1 TO count.

ENDWHILE.

the value of syuzeit is not changed at all, which means the condition (c_syuzeit > sy-uzeit) will remain true for ever (or until count is overflown)

0 Kudos

well I thought the sy-uzeit is refreshed by the system automatically, isn't it like this ?

0 Kudos

>

> well I thought the sy-uzeit is refreshed by the system automatically, isn't it like this ?

But your

c_syuzeit = sy-uzeit.
c_syuzeit = c_syuzeit + time_out.

condition would also be refreshed again if sy-uzeit is refreshed by the system automatically.

means again ENDLESS loop found

Amit.

0 Kudos

>

> well I thought the sy-uzeit is refreshed by the system automatically, isn't it like this ?

yeah, you must be right. Than probably the counter was too big, could you please try with smaller, like 1?

0 Kudos

>

> Hi Fox,

I guess the endless loop will continue until Fox responds..

~Suresh

0 Kudos

>

> >

> > well I thought the sy-uzeit is refreshed by the system automatically, isn't it like this ?

>

> yeah, you must be right. Than probably the counter was too big, could you please try with smaller, like 1?

I Guess Sy-uziet would not be refreshed as the while loops goes on.

I found Sy-uziet remain same in below piece of code:

DATA: c_syuzeit TYPE sy-uzeit,
count TYPE i.
data: time_out type i value '1'.
c_syuzeit = sy-uzeit.
c_syuzeit = c_syuzeit + time_out.

(Break-point)WHILE c_syuzeit > sy-uzeit.
ADD 1 TO count.
ENDWHILE.

PS:since Function would not be called in Recursive way.

Amit.

0 Kudos

>

> I Guess Sy-uziet would not be refreshed as the while loops goes on.quote}

I have also read it somewhere, I just could not find it now.

I tried the following piese of code and sy-uzeit changes:

WRITE : / sy-uzeit.

WAIT UP TO 2 SECONDS.

WRITE : / sy-uzeit.

So, probably in some cases it changes, in some not. Would be great to know exactly when

0 Kudos

>

> >

> > I Guess Sy-uziet would not be refreshed as the while loops goes on.quote}

>

> I have also read it somewhere, I just could not find it now.

>

> I tried the following piese of code and sy-uzeit changes:

> WRITE : / sy-uzeit.

> WAIT UP TO 2 SECONDS.

> WRITE : / sy-uzeit.

>

> So, probably in some cases it changes, in some not. Would be great to know exactly when

My quess is that wait up to n seconds is just a sap macro (such as break username) which actually uses the get time statement in order to calculate the seconds.

Kostas

Former Member
0 Kudos

Hi,

in this:

WHILE c_syuzeit > sy-uzeit.

ADD 1 TO count.

ENDWHILE.

You don't change any value of c_syuzeit and sy-uzeit, therefore you get an endless loop.

Change any value of them an insert an exit-contition.

Regards, Dieter

0 Kudos

Yes but sy-uzeit will be chenged

0 Kudos

this is not correct since

c_syuzeit = sy-uzeit.

c_syuzeit = c_syuzeit + time_out.

are not part of the loop

0 Kudos

Hi,

sy-uzeit will not refresh automatically. You should add the get time statement.

e.g

DATA: c_syuzeit TYPE sy-uzeit,
count TYPE i.

c_syuzeit = sy-uzeit.
c_syuzeit = c_syuzeit + time_out.

WHILE c_syuzeit > sy-uzeit.
get time.
ADD 1 TO count.
ENDWHILE.

Kostas

0 Kudos

Hi Kami,

Well Well Well!!!!!!!!

I got the mistake u r doing.

Check below code.


DATA: time TYPE sy-uzeit,
      counter TYPE i.
time = sy-uzeit + 3.

WHILE time > sy-uzeit.
ADD 1 TO counter.
ENDWHILE.
WRITE:/1 'counter = ', counter.

Just debug this code. It works fine without any issues.

But if u directly execute the same code it gives timeout.

Here is the explanation.

When u debug for each statement COMMIT WORK will be executed and system fields will be updated like date, time.

(U can see the status message COMMIT WORK executed by the system.) But when u execute directly COMMIT WORK happend for the whole code once.

So sy-uzeit will ramain same in the loop.

So this condition will never fails.

Hope u understand.

Thanks,

Vinod.

Former Member
0 Kudos

Hello

1. Declare count TYPE p.

2. Quite unnecessary increase counter. Try simple count = 0.

Former Member
0 Kudos

Use ABAP command WAIT seconds

0 Kudos

that would process synchronous processing and this is not expected.

johndeconinck
Participant
0 Kudos

Hi,

Sy-uzeit will always contain the time the report has been launched (it will not change during runtime). To update this variable you can use the ABAP command "GET TIME".

Kind regards,

John.

0 Kudos

Thanks John

former_member194797
Active Contributor
0 Kudos

see note 24094:

Summary

Symptom

Although a program runs for what is clearly a long time, the System time field remains at the same value.

Cause and prerequisites

The system time is only occasionally updated (usually only after screen display).

Solution

Use the key word GET TIME, ....

. . .

Header Data

Release Status:

Released on: 31.07.1995 22:00:00

Priority:

Category:

Primary Component: BC-ABA

Affected Releases

Release-Independent