  Selecting Single Process as Primary? (Batch) 
 The Question is:
 
Hello,
 
Please so kind and provide some hints how to avoid a double (or more) run of a
 batch job in the same queue.
Especial during submitting =&gt; some DCL code will detect all entries if the job
 and deletes it then a new entry will be created
 
Such as...
$ sho queue/batch/all sys_batch
Batch queue SYS_BATCH, available, on TAMDHU::
 
  Entry  Jobname         Username             Status
  -----  -------         --------             ------
    812  TEST_Q          SYSDAVO              Executing
    813  TEST_Q          SYSDAVO              Executing
    784  IKEA_ACCOUNTING_ZIP
                         SYSTEM               Holding until  1-AUG-2002 00:05:00
    807  TEST_TST_1      SYSDAVO              Holding
    808  TEST_Q          SYSDAVO              Holding
    809  TEST_Q          SYSDAVO              Holding
    810  TEST_Q          SYSDAVO              Holding
    811  TEST_Q          SYSDAVO              Holding
 
 
Here are my unsucessful attempt:
$!-----------------------------------------------------------------------------
$!
$  queue := SYS_BATCH                   ! Queue to look in
$  job   := TEST_Q                              ! Job name to look for
$  temp   = F$GETQUI("CANCEL_OPERATION")        ! Clear context
$!
$  SHOW QUEUE/ALL 'queue'
$!
$  get_context = F$GETQUI("DISPLAY_QUEUE",,queue,"WILDCARD")
$!
$NEXT_JOB:
$  jname  = F$GETQUI("DISPLAY_JOB","JOB_NAME",,"ALL_JOBS")
$  IF jname .EQS. "" THEN GOTO NO_MORE_JOBS
$  IF jname .NES. job THEN GOTO NEXT_JOB
$!!  jname = F$GETQUI("DISPLAY_JOB","JOB_NAME",,"FREEZE_CONTEXT")
$  entry = F$GETQUI("DISPLAY_JOB","ENTRY_NUMBER",,"FREEZE_CONTEXT,ALL_JOBS")
$  SHOW ENTRY/FULL 'entry'
$!  GOTO NEXT_JOB  ! =&gt; ! %JBC-E-NOQUECTX, no queue context...
$!
$NO_MORE_JOBS:
$!!  IF F$MODE() .EQS. "INTERACTIVE" THEN GOTO RESCHEDULE
$!
$!
$RESCHEDULE:
$ SET VERIFY
$ EXIT
$!-----------------------------------------------------------------------------
 
------------------------------------------------
Investigations:
 
  The OpenVMS Wizard will assume this question is specific to the
  queue manager entries, and would recommend existing discussions
  of the f$getqui lexical including the following topics: (813),
  (1240), (2159), (3951), (4546), (4568), (4903), (5188), (5471),
  (5567), (5651), (5793), (5982), (6315), (6877), (6944), etc.
 
 Answer written or last revised on  11-JAN-2002
------------------------------------------------
Suggestions:
Please improve the example area of the F$GETQUI by presenting some more
 pratical oriented sample =&gt; such my question.
In general the documentation is good but difficult to go through and it is NOT
 easy to see what needs a CONTEXT and what not etc.
 
I appreciate your advice.
Thanks a lot
Regards
   Andreas
 
 
 The Answer is :
 
  Dedicate a single-slot batch queue to the application?
 
  Use the job restart capabilities, and don't resubmit?
 
  Use a job-scheduling package, either commercial or Freeware?
 
  Use a lock (eg: open a known file exclusively) to coordinate
  (ie prevent) parallel activity?
 
  Use the following?
 
 
$       verify = 'f$verify(0)
$!*************************************************************************
$!
$! FILE: IS_JOB_IN_BATCH.COM
$!
$!      This command procedure will determine if a specified job is in the
$!      batch queue.  The job is specified by the following parameters:
$!
$!              P1 = The username of the job
$!              P2 = The name of the job
$!              P3 = The name of the batch queue to look in (optional)
$!
$!      A global symbol JOB_IN_QUEUE is set to TRUE or FALSE to indicate if
$!      the job was found.  If P1 or P2 are not specified then JOB_IN_QUEUE
$!      is set to the string "INVALID PARAMETERS".
$!
$!      A global symbol JOB_ENTRY_NUMBER is set to the entry number of the
$!      job, if found.  This symbol is set to blank otherwise.
$!
$!	If a matching job is found, this procedure will exit with a
$!	success status.
$!
$!*************************************************************************
$SS_NORMAL = 1
$SS_BADPARAM = 20
$SS_NOSUCHENTRY = 10156 + %X10000000
$!
$! Get input Parameters
$!-----------------------
$username = p1
$jobname = p2
$batch_queue = P3
$!
$!
$JOB_ENTRY_NUMBER == ""
$status = SS_NOSUCH_ENTRY
$!
$! Check for invalid parameters
$!------------------------------
$if username .eqs. "" .or. jobname .eqs. ""
$then
$   job_in_queue == "INVALID PARAMETERS"
$   status = SS_BADPARAM
$   goto all_exit
$endif
$!
$if batch_queue .eqs. "" then batch_queue = "*"
$!
$!
$! Clear out the queue context
$!-----------------------------
$temp = f$getqui("cancel_operation")
$!
$!
$job_flags = "batch,timed_release_jobs,all_jobs"
$freeze_job_flags = "batch,timed_release_jobs,freeze_context,all_jobs"
$!
$! Search for the job
$!-----------------------
$queue_loop:
$!
$!  Check each queue in sequence
$!------------------------------
$   qname = f$getqui ("display_queue","queue_name",batch_queue,"wildcard")
$   if qname .eqs. "" then goto queue_loop_end
$job_loop:
$!
$!      Check each job on the queue
$!----------------------------------
$       noaccess = f$getqui("display_job","job_inaccessible",,job_flags)
$       if noaccess .eqs. "TRUE" then goto job_loop
$       if noaccess .eqs. "" then goto queue_loop
$!
$!	Freeze the queue context to get job detail
$!-------------------------------------------------
$       jname = f$getqui("display_job","job_name",,freeze_job_flags)
$       juser = f$getqui("display_job","username",,freeze_job_flags)
$       jentry = f$getqui("display_job","entry_number",,freeze_job_flags)
$       if jname .eqs. jobname
$       then
$           if (username .eqs. "*") .or. (juser .eqs. username)
$           then
$               goto job_found
$           endif
$       endif
$       goto job_loop
$!
$queue_loop_end:
$   job_in_queue == "FALSE"
$   goto all_exit
$!
$job_found:
$   job_in_queue == "TRUE"
$   JOB_ENTRY_NUMBER == 'jentry'
$   status = SS_NORMAL
$!
$!
$all_exit:
$    temp = f$getqui("cancel_operation")
$    verify = f$verify(verify)
$    exit 'status'
 
 Answer written or last revised on  10-JUL-2002 
