Calculate the runtime with ABAP

Calculate the runtime with ABAP

Calculate runtime in microseconds :


DATA: lw_t1          TYPE i,
      lw_t2          TYPE i,
      lw_elapsed     TYPE i.
 
* Get the time and put in lw_t1.
GET RUN TIME FIELD lw_t1.
 
* Wait 3 seconds.
CALL FUNCTION 'ENQUE_SLEEP'
  EXPORTING
    SECONDS = 3.
 
* Get the time and put in lw_t2.
GET RUN TIME FIELD lw_t2.
 
* Calculate the different between lw_t2 and lw_t1.
lw_elapsed = lw_t2 - lw_t1.          " In microseconds.
lw_elapsed = ELAPSED / 1000000.      " In seconds.
 
* Display the runtime.
WRITE:/ ' Runtime =', lw_elapsed, 'seconds'.

If your measure may overload 36 min, do not store the run time in a type i (integer) variable.
You should use a type numeric, like :


DATA: lw_t1(200)          TYPE n,

About the author

fjourneau administrator

Hi, I'm Florian Journeau, SAP ABAP R3 Freelance, based in Toulouse, France. You want to know more about me, have a look on my CV : cv.fjourneau.net.

Leave a Reply