Dennis Röttger
Dennis Röttger

Reputation: 1985

WAIT UP TO <milliseconds> in ABAP

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?

Upvotes: 4

Views: 13356

Answers (4)

wcjos
wcjos

Reputation: 1

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.

Upvotes: 0

gurehbgui
gurehbgui

Reputation: 14694

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.

Upvotes: 6

phil soady
phil soady

Reputation: 11348

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.

Upvotes: -2

Dennis Röttger
Dennis Röttger

Reputation: 1985

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.

Upvotes: -2

Related Questions