4

According to ABAP Documentation, the command WAIT UP TO x SECONDS needs an operand of type i. However, I'd like to WAIT UP TO x Milliseconds or something similar. Neither official documentation nor several other forum posts have been helpful thus far.

Is there any way to specify a wait for a fraction of a second?

Dennis Röttger
  • 1,975
  • 6
  • 32
  • 51
  • Does this answer your question? [How to make an abap program pause?](https://stackoverflow.com/questions/396663/how-to-make-an-abap-program-pause) – Sandra Rossi Dec 31 '19 at 20:50

4 Answers4

5

You can simply pass a decimal value like:

WAIT UP TO '0.5' SECONDS

or something like:

WAIT UP TO '0.01' SECONDS

See also How to make an abap program pause.

Florian
  • 4,821
  • 2
  • 19
  • 44
gurehbgui
  • 14,236
  • 32
  • 106
  • 178
0

If you want to avoid implicit commit with WAIT UP TO, create a simple RFC function:

FUNCTION ZSLEEP .
*"--------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     VALUE(DURATION) TYPE  SDURATION_SECONDS
*"--------------------------------------------------------------------

* To wait 50 milliseconds write this:
*   DATA duration TYPE sduration_seconds VALUE '0.050'.
*   CALL FUNCTION 'ZSLEEP' DESTINATION 'NONE' KEEPING LOGICAL UNIT OF WORK EXPORTING duration = duration.

WAIT UP TO duration SECONDS.

ENDFUNCTION.
Aelius
  • 1,029
  • 11
  • 22
wcjos
  • 1
-2

I've just solved it like this:

DATA: timestart TYPE timestampl,
  timeend TYPE timestampl,
  millisecs TYPE timestampl,
  imilli TYPE i VALUE 200.



GET TIME STAMP FIELD timestart.

  millisecs = imilli / 1000.

  timestart = timestart + millisecs.

  DO.
    GET TIME STAMP FIELD timeend.
    IF timestart < timeend.
      EXIT.
    ENDIF.
  ENDDO.

  WRITE timeend.

If I now rewrite this as a function taking an integer as an import parameter (in place of imilli) I'll - to my knowledge - have exactly what I wanted.

I'll leave this up for a little before tagging it as the correct answer in the hopes that someone may have a better / more elegant solution.

Dennis Röttger
  • 1,975
  • 6
  • 32
  • 51
  • 1
    This is called a busy waiting loop and is a terribly bad idea, because your code will occupy the CPU with checking the time as long as it's waiting. It will work for small samples and experiments, but please don't use this for anything serious. – Joachim Sauer Jan 07 '20 at 08:40
  • Thanks for the comment, Joachim. As I said my result was less than optimal, however I haven't had the pleasure of finding a better result yet (on older systems where "wait up to" only works with integers). Would you care to explain one? – Dennis Röttger Feb 16 '20 at 12:21
  • Sorry, my knowledge of ABAP is very superficial, so I don't know the specific tools you have access to. – Joachim Sauer Feb 16 '20 at 15:08
-2

Without asking about the requirement, 2 ways to do this are

  • GET RUN TIME
    where SET RUN TIME CLOCK RESOLUTION can be important.

or

  • GET TIME STAMP using a target field TIMESTAMPL

Do not use WAIT UP TO for fine time frames due to the Workprocess switching. Wait also carries other side effects not immediately obvious.

phil soady
  • 11,043
  • 5
  • 50
  • 95