Extending COBOL to .NET and Java
User group seeks sponsors for future

Kill a job, if it's already running

We have loads of jobs that would cause damage if more than one copy was run. To prevent this we have the following code at the start of them:

  !if jobcnt('jobname,user.account') > 1 then
  !  tellop WARNING: Job is already running. I'm terminating.
  !  eoj
  !  endif

A couple of system problems have resulted in a large backlog of jobs waiting to run. One of our jobs is never getting past the above check — because by the time it moves from WAIT to EXEC, our scheduler has streamed the next copy which joins the WAIT queue.

One way I can see around this is to do the following instead (we have VEsoft's MPEX):

  !setjcw mpexfaststart 1
  %if jscount('jobname,user.account&EXEC') > 1 then
  %  tellop WARNING: Job is already running. I'm terminating.
  %  eoj
  %  endif
  !setjcw mpexfaststart 0

But how do we terminate a job already running, if we don't have MPEX?

Tony Summers replies:

One method is to build a file at the start of each job and/or check for the file's existence in the same job.

Here’s a clip (MPE information removed for security) of one of our job streams that ensures that certain jobs run in a particular order, but there are ways of adapting it to suit your requirement.

Also remember that a job will normally flush/terminate if any line of JCL fails — thus it might be just as effective to build a named file at the start of the job and purge it as the job logs off. You have to ensure that autocontinue is NOT turned on.

!comment start up
!IF  NOT FINFO("STEODPT6.group.account",0)
!    UDCFAIL "Part 6 has not run "
!    EOJ
!IF  FINFO("SEEODPT6.group.account",0)
!    UDCFAIL "Part 6 did not complete "
!    EOJ
!BUILD STEODPT7.group.account
!BUILD SEEODPT7.group.account
!comment <add your code here >
!PURGE SEEODPT7.group.account