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: 

Jobs running in parallel

Former Member
0 Kudos
117

Hi every body

I have scheduled a job to be executed every 5 minutes.

The problem is that when the job is delayed two instances of the jobs are running in parallel and I want to avoid this, only one instance of the job can be running.

How can I do that??

Regards

1 REPLY 1

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
38

There is a couple ways to handle this. One is to use a lock object for the program. You can put this code in the start of the program, and any time it is executed it will perform a ENQUEUE, which places a lock on this program. Then if it is executed again while running, the program will simply end without doing any further processing.

DATA: lv_repid TYPE sy-repid.

lv_repid = sy-repid.

* Create program lock
CALL FUNCTION 'ENQUEUE_E_DSVAS_TRDIR'
  EXPORTING
*   MODE_TRDIR           = 'X'
    name                 = lv_repid
*   X_NAME               = ' '
*   _SCOPE               = '2'
*   _WAIT                = ' '
*   _COLLECT             = ' '
 EXCEPTIONS
   foreign_lock         = 1
   system_failure       = 2
   OTHERS               = 3.
* If lock could not be achieved, means program is already running,
* so leave program now.
IF sy-subrc <> 0.
  LEAVE PROGRAM.
ENDIF.


* Do normal program processsing here.

* Now release the lock.
CALL FUNCTION 'DEQUEUE_E_DSVAS_TRDIR'
 EXPORTING
*   MODE_TRDIR       = 'X'
    name             = lv_repid.
*   X_NAME           = ' '
*   _SCOPE           = '3'
*   _SYNCHRON        = ' '
*   _COLLECT         = ' '

Regards,

Rich Heilman