2010 Jan 04 3:20 PM
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
2010 Jan 04 3:36 PM
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