Get the entry number of a batch job

Post Reply

Topic author
mjimji
Contributor
Posts: 13
Joined: Thu Oct 22, 2020 11:24 am
Reputation: 0
Status: Offline

Get the entry number of a batch job

Post by mjimji » Thu Oct 22, 2020 11:35 am

Is there a (simple) way of getting the entry number of a batch job from within the job?
Thanks,
Mark


sms
Master
Posts: 497
Joined: Fri Aug 21, 2020 5:18 pm
Reputation: 0
Status: Offline

Re: Get the entry number of a batch job

Post by sms » Thu Oct 22, 2020 2:49 pm

Code: Select all

> Is there a (simple) way [...]

   Define "simple".

      HELP LEXICALS F$GETQUI   ! (Abandon hope, ...)

its $ submit /noprint qe.com /log = []qe.log
Job qe (queue SYS$BATCH_ITS, entry 963) started on SYS$BATCH_ITS
its $ 

Job qe (queue SYS$BATCH_ITS, entry 963) completed

its $ type qe.log
$ Set NoOn
$ VERIFY = F$VERIFY(F$TRNLNM("SYLOGIN_VERIFY"))
      entry: 963
  SMS          job terminated at 22-OCT-2020 13:39:50.38

  Accounting information:
  Buffered I/O count:                102      Peak working set size:       4672
  Direct I/O count:                   47      Peak virtual size:         178112
  Page faults:                       367      Mounted volumes:                0
  Charged CPU time:        0 00:00:00.03      Elapsed time:       0 00:00:00.10

its $ type qe.com
$!              function         item            object-id   flags
$ e = f$getqui( "DISPLAY_ENTRY", "ENTRY_NUMBER",           , "THIS_JOB")
$!
$ write sys$output "      entry: ''e'"

User avatar

cct
Master
Posts: 256
Joined: Sat Aug 15, 2020 9:00 am
Reputation: 0
Location: Cambridge, UK
Status: Offline

Re: Get the entry number of a batch job

Post by cct » Fri Oct 23, 2020 7:52 am

Yes, f$getqui can be a bit daunting at first!

However there is a much simpler way - look for the local symbol $ENTRY

Code: Select all

$ create test.com
write sys$output "Test"
 ^Z
$ show symb $entry
%DCL-W-UNDSYM, undefined symbol - check validity and spelling
$ subm/keep test
Job TEST (queue SYS$BATCH, entry 1) started on SYS$BATCH
$ show symb $entry
  $ENTRY = "1"
$
Chris
Chris Townley
VMS Ambassador


sms
Master
Posts: 497
Joined: Fri Aug 21, 2020 5:18 pm
Reputation: 0
Status: Offline

Re: Get the entry number of a batch job

Post by sms » Fri Oct 23, 2020 1:11 pm

Code: Select all

> $ show symb $entry
>   $ENTRY = "1"

   Now try that "from within the job".


Topic author
mjimji
Contributor
Posts: 13
Joined: Thu Oct 22, 2020 11:24 am
Reputation: 0
Status: Offline

Re: Get the entry number of a batch job

Post by mjimji » Thu Jan 14, 2021 5:23 am

Hi sms,
A much delayed response, but thanks for your answer and I think it qualifies as "simple"!
Regards,
Mark


jon.pinkley
Member
Posts: 9
Joined: Sun Nov 10, 2024 4:15 pm
Reputation: 0
Status: Offline

Re: Get the entry number of a batch job

Post by jon.pinkley » Tue Nov 12, 2024 5:31 pm

Sorry for necro-posting, but I read the request as is there a way for a running batch job to get it's own entry number.

And the answer to that question is a relatively simple f$getqui call

$ this_entry = f$getqui("display_job","entry_number",,"this_job")


sms
Master
Posts: 497
Joined: Fri Aug 21, 2020 5:18 pm
Reputation: 0
Status: Offline

Re: Get the entry number of a batch job

Post by sms » Tue Nov 12, 2024 6:35 pm

Code: Select all

> $ this_entry = f$getqui("display_job","entry_number",,"this_job")

   I'll bite.  How is that superior to this?:

> $!              function         item            object-id   flags
> $ e = f$getqui( "DISPLAY_ENTRY", "ENTRY_NUMBER",           , "THIS_JOB")


jon.pinkley
Member
Posts: 9
Joined: Sun Nov 10, 2024 4:15 pm
Reputation: 0
Status: Offline

Re: Get the entry number of a batch job

Post by jon.pinkley » Thu Nov 14, 2024 7:54 pm

sms wrote:
Tue Nov 12, 2024 6:35 pm

Code: Select all

> $ this_entry = f$getqui("display_job","entry_number",,"this_job")

   I'll bite.  How is that superior to this?:

> $!              function         item            object-id   flags
> $ e = f$getqui( "DISPLAY_ENTRY", "ENTRY_NUMBER",           , "THIS_JOB")
Until you posted the above reply, I hadn't scrolled to the very end of your code block in your first post in this thread.

I have always used "DISPLAY_JOB", probably because I saw an example somewhere that used that. Perhaps in an old DSN (Digital Software Network) posting, or something from comp.os.vms

At any rate, I have been using that syntax for a very long time, much earlier than this post on what used to be the HP ITRC
https://community.hpe.com/t5/operating- ... -p/5054380

Since I found that it worked, it's been "cut and paste" when I need it.

And I can't see any difference between DISPLAY_ENTRY and DISPLAY_JOB, although I agree that if you were reading the output of help lexica f$getqui it would seem that DISPLAY_ENTRY would be the appropriate one to use., because it says that to use DISPLAY_JOB requires setting up getqui queue context. But for flags set to "THIS_JOB" it must use a separate context, or reset the context, because it works without any previous calls to f$getqui. See the last paragraph of the
Nonwildcard Mode here https://www0.mi.infn.it/~calcolo/OpenVM ... bottom_043

"Finally, the $GETQUI service provides an option that allows a batch job to obtain information about the queue, job, or command file that the associated batch job is executing without first entering wildcard mode to establish a queue or job context. You can make a call from the batch job that specifies the QUI$_DISPLAY_QUEUE function code to obtain information about the queue from which the batch job was initiated; the QUI$_DISPLAY_JOB function code to obtain information about the batch job itself; or the QUI$_DISPLAY_FILE function code to obtain information about the command file for the batch job. For each of these calls, you must select the QUI$V_SEARCH_THIS_JOB option of the QUI$_SEARCH_FLAGS item code. When you select this option, $GETQUI ignores all other options in the QUI$_SEARCH_FLAGS item code."

That's probably where I got the "DISPLAY_JOB" from, but I really don't remember. Both dislay_job and display_entry appear to behave the same with f$getqui on both Alpha V8.3 and IA64 V8.4-2L1

My biggest gripe with f$getqui is the single "process global queue context". And the DCL Lexical function f$getqui uses the same default context as the DCL command show queue and show entry do.

See https://wiki.vmssoftware.com/F$GETQUI_Context

So trying to debug dcl command procedures that use f$getqui with wildcard context by using things like "show queue" can clobber the context used by f$getqui. Your comment in your previous post was spot on:

"HELP LEXICALS F$GETQUI ! (Abandon hope, ...)"

test example follows: first the command procedure test_getqui.com

Code: Select all

HP$ type test_getqui.com;
$ ver = 'f$verify(0)'
$ if f$edit(p1,"upcase,trim") .eqs. "VERIFY" then set verify
$ if f$environment("verify_procedure")
$ then
$   sym   = "show symbol"
$   dbgwr = "write sys$output"
$   ifdbg = ""
$ else
$   sym   = "!show symbol"
$   dbgwr = "!write sys$output"
$   ifdbg = "!"
$ endif
$
$ ts=f$time()
$ this_proc = f$environment("procedure")
$ this_name = f$parse(this_proc,,,"name")
$ this_username = f$edit(f$getjpi("","username"),"trim")
$ this_pid = f$getjpi("","pid") ! for temp rename
$ this_mode = f$mode()
$ mcr utility_exe:ppf sys$output ! logfile name is now in fid_file_name
$ sym *file_name/local
$ this_logfile = "''fid_file_name'"
$ this_job_entry  = f$getqui("display_job","entry_number",,"this_job")
$ this_job_jobname = f$getqui("display_job","job_name",,"this_job")
$ this_job_jobname_proc = f$getqui("display_file","file_specification",,"this_job")
$ this_job_queue = f$getqui("display_job","queue_name",,"this_job")
$ this_job_restart_queue = f$getqui("display_job","restart_queue_name",,"this_job")
$ this_job_param1 = f$getqui("display_job","parameter_1",,"this_job")
$ this_job_after = f$getqui("display_job","after_time",,"this_job")
$ this_entry_entry  = f$getqui("display_entry","entry_number",,"this_job")
$ this_entry_jobname = f$getqui("display_entry","job_name",,"this_job")
$ this_entry_jobname_proc = f$getqui("display_file","file_specification",,"this_job")
$ this_entry_queue = f$getqui("display_entry","queue_name",,"this_job")
$ this_entry_restart_queue = f$getqui("display_entry","restart_queue_name",,"this_job")
$ this_entry_param1 = f$getqui("display_entry","parameter_1",,"this_job")
$ this_entry_after = f$getqui("display_entry","after_time",,"this_job")
$ sho symbol /loc *
$ exit 1+0*f$verify(ver)
HP$
HP$ submit/que=delta$oper/noprint/log=scr test_getqui /param=verify
Job TEST_GETQUI (queue DELTA$OPER, entry 1002945) started on DELTA$OPER
HP$

Here's the resulting log file

Code: Select all

HP$ type scr:test_getqui.log
$ if f$environment("verify_procedure")
$ then
$   sym   = "show symbol"
$   dbgwr = "write sys$output"
$   ifdbg = ""
$ else
$ endif
$
$ ts=f$time()
$ this_proc = f$environment("procedure")
$ this_name = f$parse(this_proc,,,"name")
$ this_username = f$edit(f$getjpi("","username"),"trim")
$ this_pid = f$getjpi("","pid") ! for temp rename
$ this_mode = f$mode()
$ mcr utility_exe:ppf sys$output ! logfile name is now in fid_file_name
$ sym *file_name/local
  FID_FILE_NAME = "DISK$USER1:[USERS.JON.SCRATCH]TEST_GETQUI.LOG;6"
  ORG_FILE_NAME = "DSA1200:[USERS.][JON.SCRATCH]TEST_GETQUI.LOG;6"
  PHY_FILE_NAME = "DSA1200:[USERS.][JON.SCRATCH]TEST_GETQUI.LOG;6"
$ this_logfile = "DISK$USER1:[USERS.JON.SCRATCH]TEST_GETQUI.LOG;6"
$ this_job_entry  = f$getqui("display_job","entry_number",,"this_job")
$ this_job_jobname = f$getqui("display_job","job_name",,"this_job")
$ this_job_jobname_proc = f$getqui("display_file","file_specification",,"this_job")
$ this_job_queue = f$getqui("display_job","queue_name",,"this_job")
$ this_job_restart_queue = f$getqui("display_job","restart_queue_name",,"this_job")
$ this_job_param1 = f$getqui("display_job","parameter_1",,"this_job")
$ this_job_after = f$getqui("display_job","after_time",,"this_job")
$ this_entry_entry  = f$getqui("display_entry","entry_number",,"this_job")
$ this_entry_jobname = f$getqui("display_entry","job_name",,"this_job")
$ this_entry_jobname_proc = f$getqui("display_file","file_specification",,"this_job")
$ this_entry_queue = f$getqui("display_entry","queue_name",,"this_job")
$ this_entry_restart_queue = f$getqui("display_entry","restart_queue_name",,"this_job")
$ this_entry_param1 = f$getqui("display_entry","parameter_1",,"this_job")
$ this_entry_after = f$getqui("display_entry","after_time",,"this_job")
$ sho symbol /loc *
  DBGWR = "write sys$output"
  FID_FILE_NAME = "DISK$USER1:[USERS.JON.SCRATCH]TEST_GETQUI.LOG;6"
  IFDBG = ""
  ORG_FILE_NAME = "DSA1200:[USERS.][JON.SCRATCH]TEST_GETQUI.LOG;6"
  P1 = "VERIFY"
  P2 = ""
  P3 = ""
  P4 = ""
  P5 = ""
  P6 = ""
  P7 = ""
  P8 = ""
  PHY_FILE_NAME = "DSA1200:[USERS.][JON.SCRATCH]TEST_GETQUI.LOG;6"
  SYM = "show symbol"
  THIS_ENTRY_AFTER = "14-NOV-2024 13:19:04.54"
  THIS_ENTRY_ENTRY = 1002945   Hex = 000F4DC1  Octal = 00003646701
  THIS_ENTRY_JOBNAME = "TEST_GETQUI"
  THIS_ENTRY_JOBNAME_PROC = "_DSA1200:[USERS.JON.SCRATCH]TEST_GETQUI.COM;5"
  THIS_ENTRY_PARAM1 = "VERIFY"
  THIS_ENTRY_QUEUE = "DELTA$OPER"
  THIS_ENTRY_RESTART_QUEUE = "DELTA$OPER"
  THIS_JOB_AFTER = "14-NOV-2024 13:19:04.54"
  THIS_JOB_ENTRY = 1002945   Hex = 000F4DC1  Octal = 00003646701
  THIS_JOB_JOBNAME = "TEST_GETQUI"
  THIS_JOB_JOBNAME_PROC = "_DSA1200:[USERS.JON.SCRATCH]TEST_GETQUI.COM;5"
  THIS_JOB_PARAM1 = "VERIFY"
  THIS_JOB_QUEUE = "DELTA$OPER"
  THIS_JOB_RESTART_QUEUE = "DELTA$OPER"
  THIS_LOGFILE = "DISK$USER1:[USERS.JON.SCRATCH]TEST_GETQUI.LOG;6"
  THIS_MODE = "BATCH"
  THIS_NAME = "TEST_GETQUI"
  THIS_PID = "2181235F"
  THIS_PROC = "DISK$USER1:[USERS.JON.SCRATCH]TEST_GETQUI.COM;5"
  THIS_USERNAME = "JON"
  TS = "14-NOV-2024 13:19:04.68"
  VER = 0   Hex = 00000000  Octal = 00000000000
$ exit 1+0*f$verify(ver)
  JON          job terminated at 14-NOV-2024 13:19:04.69

  Accounting information:
  Buffered I/O count:                154      Peak working set size:       5632
  Direct I/O count:                  174      Peak virtual size:         193696
  Page faults:                       685      Mounted volumes:                0
  Charged CPU time:        0 00:00:00.08      Elapsed time:       0 00:00:00.11
HP$
Last edited by jon.pinkley on Thu Nov 14, 2024 10:47 pm, edited 2 times in total.

Post Reply