Skip to Content
-1

How to Avoid same background job running twice

Apr 27, 2017 at 11:11 AM

294

avatar image

Dear Friends,

Can anybody tell how to avoid same job running twice at the same time. I made a report that is supposed to be run in background. But the report should run per job and new job only starts when there is no other active job is running. Please help in this regards.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Raymond Giuseppi
Apr 27, 2017 at 11:40 AM
0

Usually I add a first step with a program that checks for other instance of the background job currently running.

* Current job information
  call function 'GET_JOB_RUNTIME_INFO'
    importing
      jobcount = gv_jobcount
      jobname  = gv_jobname
    exceptions
      others   = 0.
* Don't allow concurrent run
  select single tbtco~jobname into gv_job
    from tbtco
    where jobname EQ gv_jobname
      and jobcount ne gv_jobcount " me
      and status = 'R'.
  if sy-subrc eq 0. " message in log and exit job

You can also rely on some program name instead of job name, join tbtco with tbtcp.

Another solution was to rely on some locking, but could be broken by some commit.

Show 4 Share
10 |10000 characters needed characters left characters exceeded

Thanks very much for your reply Raymond. Appreciate that. Tell me one thing please. I know the job name but how can i get job count? Additionally, when ever we run a background job, the job count is different? Isn't it? So which job count I am supposed to pass to this FM? Please let me know.

0

Did you notice the 'importing' tag in the first FM call, those are exported parameters, so caller import those ;-)

1

Thanks Raymond. And one last thing please. Shall i write this code in INITIALIZATION part or in START OF SELECTION? what do you recommend?

0

In my systems there a single utility program used in multiple jobs as the first step (with some parameters available for other selection criteria and delay options)

To add the function inside the called program, you could always use LOAD-OF-PROGRAM or INITIALIZATION for report programs.

1
John Vo Apr 27, 2017 at 11:21 AM
0

Hi Ijaz

try to set up the job with daily , weekly ... usually the time run report will not exceed one day.

then it will not conflict

Thanks,

John

Share
10 |10000 characters needed characters left characters exceeded
Evgeny Gubenko Apr 27, 2017 at 11:36 AM
0

Hi!

Also you can try to get job status by calling FM BP_JOB_SELECT_SM37B.

Evgeny

Share
10 |10000 characters needed characters left characters exceeded
Always Learner Apr 28, 2017 at 07:42 AM
0

Hi Ijaz,

The report RSBTONEJOB2 can serve your purpose. This report is to ensure that only one instance of a job is running.

Thanks

Share
10 |10000 characters needed characters left characters exceeded