From:	RTPARK::RLB  "Bob Boyd 8*565-3627  27-Jul-1988 1641" 27-JUL-1988 17:31
To:	ALL_MANAGERS,RLB         
Subj:	Corrected version of F$GETQUI example -- mystery solved

Message created @ 27-JUL-1988 16:32:31.41

I posted a sample command procedure using F$GETQUI yesterday or the day
before.  

It has been frustrating...but the answer is now clear as to why information
was turning up missing.

It turns out that there is a little bit of complication to F$GETQUI and 
JOB context -- even though you've established a job context, due to the 
fact you're not making one big call for all the info using a long item
list as in calling the $GETQUI service from an image -- you must specify
the ALL_JOBS search flag on the subsequent calls for informational items.

Here is a corrected and slightly cleaner version of the procedure I posted
yesterday.

We plan to put the same capability into an image now that I've demonstrated
what we set out to do.

Also, for those of you who are concerned about VMS_SHARE -- it still works
under V5.0.0.

================================ 8< cut here ================================
$!..............................................................................
$! VAX/VMS archive file created by VMS_SHAR V-5.01 01-Oct-1987
$! which was written by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au)
$! To unpack, simply save and execute (@) this file.
$!
$! This archive was created by RLB
$! on Wednesday 27-JUL-1988 16:29:54.35
$!
$! It contains the following 1 file:
$! DISPLAY_QUI.COM
$!==============================================================================
$ Set Symbol/Scope=(NoLocal,NoGlobal)
$ Version=F$GetSYI("VERSION") ! See what VMS version we have here:
$ If Version.ges."V4.4" then goto Version_OK
$ Write SYS$Output "Sorry, you are running VMS ",Version, -
                ", but this procedure requires V4.4 or higher."
$ Exit 44
$Version_OK: CR[0,8]=13
$ Pass_or_Failed="failed!,passed."
$ Goto Start
$Convert_File:
$ Read/Time_Out=0/Error=No_Error1/Prompt="creating ''File_is'" SYS$Command ddd
$No_Error1: Define/User_Mode SYS$Output NL:
$ Edit/TPU/NoSection/NoDisplay/Command=SYS$Input/Output='File_is' -
        VMS_SHAR_DUMMY.DUMMY
f:=Get_Info(Command_Line,"File_Name");b:=Create_Buffer("",f);
o:=Get_Info(Command_Line,"Output_File");Set(Output_File,b,o);
Position(Beginning_of(b));Loop x:=Erase_Character(1);Loop ExitIf x<>"V";
Move_Vertical(1);x:=Erase_Character(1);Append_Line;
Move_Horizontal(-Current_Offset);EndLoop;Move_Vertical(1);
ExitIf Mark(None)=End_of(b) EndLoop;Position(Beginning_of(b));Loop
x:=Search("`",Forward,Exact);ExitIf x=0;Position(x);Erase_Character(1);
If Current_Character='`' then Move_Horizontal(1);else
Copy_Text(ASCII(INT(Erase_Character(3))));EndIf;EndLoop;Exit;
$ Delete VMS_SHAR_DUMMY.DUMMY;*
$ Checksum 'File_is
$ Success=F$Element(Check_Sum_is.eq.CHECKSUM$CHECKSUM,",",Pass_or_Failed)+CR
$ Read/Time_Out=0/Error=No_Error2/Prompt=" CHECKSUM ''Success'" SYS$Command ddd
$No_Error2: Return
$Start:
$ File_is="DISPLAY_QUI.COM"
$ Check_Sum_is=224913550
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X$ vfl = f$ver(0+f$trnlnm("debug$dcl"))
X$!
X$! F$GETQUI example
X$!
X$! Author: R.L. Boyd, GE Microelectronics Ctr.
X$! Date:   25-Jul-1988
X$! 
X$! to enable debug -- DEFINE DEBUG$DCL 1
X$!
X$ set noon
X$!
X$! Set up symbols for everything
X$! clear out any old list of inaccessible_jobs
X$!
X$ if f$type(inaccessible_list).nes."" then -
X$ `009delete/symbol/global inaccessible_list
X$!
X$! attempt to elevate privileges -- it may do some good
X$!
X$ save_privs = f$setprv("oper,world,sysprv")
X$!
X$ null = ""
X$ b = " "
X$ semi = ";"
X$ comma = ","
X$ say = "write sys$output "
X$ hdr_FORMAT = "!15AS !12AS !15AS !6AS     !8AS!/  !23AS   !23AS   !AS"
X$ JOB_FORMAT = "!15AS !12AS !15AS !6SL     !8AS!/  !23AS   !23AS   !AS"
X$!
X$ say f$fao(hdr_format,"QUEUE NAME","USERNAME","JOB NAME","ENTRY","PID",-
X`009"Submitted @","Started @","CPU Time")
X$!=====================================================================
X$! SUBROUTINES
X$!=====================================================================
X$!
X$! delete a global symbol if it exists
X$!
X$DELSYM:subroutine
X$ set symbol/scope=nolocal
X$ if f$type('p1').nes."" then $ delete/symbol/global 'p1'
X$ set symbol/scope=local
X$endsubroutine
X$! convert clunks to cpu time -- values returned by f$getjpi("","CPUTIM")
X$! p1 -- integer value to convert
X$! p2 -- optional global symbol to return the string to.
X$CONVERT_CPUTIME: subroutine
X$   cpu = p1
X$   tmp_day = cpu/(24*360000)
X$   tmp_hrs = cpu/360000-24*tmp_day
X$   tmp_min = cpu/6000-60*(24*tmp_day+tmp_hrs)
X$   tmp_sec = cpu/100-60*(60*(24*tmp_day+tmp_hrs)+tmp_min)
X$   tmp_hun = cpu - 100*(60*(60*(24*tmp_day+tmp_hrs)+tmp_min)+tmp_sec)
X$   cputim = f$fao("!2ZL-!2ZL:!2ZL:!2ZL.!2ZL",-
X`009`009 tmp_day,tmp_hrs,tmp_min,tmp_sec,tmp_hun)
X$   if p2.nes.""
X$   then 
X$`009'p2' == cputim
X$   else
X$`009 write sys$output "CPU time:  ",cputim
X$   endif
X$endsubroutine
X$!
X$! Add an inaccessible job to the list
X$!
X$INACC_ADD: subroutine
X$   if f$type(inaccessible_list).eqs.null 
X$ `009then 
X$`009  inaccessible_list == job_queue_name+comma+f$str(job_entry)
X$ `009else
X$`009  inaccessible_list == inaccessible_list+-
X`009`009semi+job_queue_name+comma+f$string(job_entry)
X$`009endif !
X$endsubroutine
X$!
X$! Get job info about a particular job -- 2 modes:
X$! `009A.`009DISPLAY_JOB for ones submitted by this user.
X$!`009B.`009DISPLAY_ENTRY for those submitted by others.
X$INFO_GET: subroutine
X$ job_user == f$getqui(type,"USERNAME",'control')
X$ job_pid  == f$getqui(type,"JOB_PID",'control')
X$ job_submit_time == f$getqui(type,"SUBMISSION_TIME",'control')
X$ job_name == f$getqui(type,"JOB_NAME",'control') 
X$ if job_pid.nes.null 
X$ then 
X$ job_cputime == f$getjpi(job_pid,"CPUTIM")
X$ job_login_time == f$getjpi(job_pid,"LOGINTIM")
X$ else
X$ job_cputime == 0
X$ job_login_time == " "
X$ endif
X$ if f$ver() then $ show symbol job*
X$ exit
X$ endsubroutine
X$!
X$! Use FAO to display the information we got
X$!
X$INFO_DISPLAY: subroutine
X$ call CONVERT_CPUTIME 'job_cputime' str_cputime
X$ say f$fao(job_format,job_queue_name,job_user,job_name,job_entry,job_pid,-
X`009job_submit_time,job_login_time,str_cputime)
X$ endsubroutine
X$!=====================================================================
X$! END OF SUBROUTINES
X$!=====================================================================
X$!
X$! Loop through all of the batch queues to look for executing jobs
X$! Then display interesting information about each one.
X$!
X$ set noon
X$!
X$! cancel any outstanding $GETQUI context
X$!
X$ type = "DISPLAY_JOB"
X$ TEMP = F$GETQUI("CANCEL_OPERATION")
X$ vax_cluster = f$getsyi("vaxcluster")
X$ if vax_cluster then $ my_scsnode = f$getsyi("scsnode")
X$!
X$! in order to get additional items about a job belonging to a different
X$! user, must use the ALL_JOBS search flag, adding FREEZE_CONTEXT of course.
X$!
X$! This is the setup used for the first pass.
X$!
X$ initial = ",""all_jobs,executing_jobs"""
X$ control = ",""all_jobs,freeze_context"""
X$!
X$! Get the next queue name, and establish context for DISPLAY_JOB function
X$!
X$QUEUE_LOOP:
X$ job_queue_name = F$GETQUI("DISPLAY_QUEUE","QUEUE_NAME","*","BATCH")
X$!
X$! See if we have a name or if we have gotten to the end of the list
X$!
X$ if job_queue_name .nes.null 
X$ then
X$!
X$! If we're in a cluster then see if it is on the current cpu or not
X$! Use FREEZE_CONTEXT to keep it on this queue.
X$!
X$ if vax_cluster
X$ then
X$`009scsnode = f$getqui("DISPLAY_QUEUE","SCSNODE_NAME",,"FREEZE_CONTEXT")
X$`009if scsnode.nes.my_scsnode then $ goto QUEUE_LOOP
X$ endif
X$ if f$ver() then $ show symbol job_queue_name
X$!
X$! Get the next job that is executing in this queue and establish
X$! context for subsequent DISPLAY_JOB calls
X$!
X$JOB_LOOP:
X$ job_entry = f$getqui("DISPLAY_JOB","ENTRY_NUMBER",'initial')
X$ if job_entry.eqs.null then $ goto QUEUE_LOOP
X$ job_inaccessible = f$getqui("DISPLAY_JOB","JOB_INACCESSIBLE",'control')
X$ if f$ver() then $ show symbol job_inaccessible
X$ jbc_status = $status
X$! save status value 
X$! Did we encounter an error?
X$ if .not.jbc_status then $ goto QUEUE_LOOP
X$ if f$ver() then $ show symbol job_entry
X$!
X$! Did we get a good entry ?
X$!
X$  if job_inaccessible 
X$  then
X$ `009call INACC_ADD
X$  else
X$ `009call INFO_GET
X$`009if (f$type(job_pid).eqs."STRING" ) .and. (job_pid.eqs.null)
X$`009then 
X$`009`009call INACC_ADD
X$`009else
X$`009 `009call INFO_DISPLAY
X$`009endif
X$  endif ! job inaccessible test -- with Privs this never works
X$  goto JOB_LOOP
X$ endif ! queue check
X$!
X$! see if we had any that were inaccessible
X$!
X$ if f$type(inaccessible_list).nes.null
X$ then
X$  if inaccessible_list.eqs.null then $ goto EXIT
X$  show symbol inaccessible_list
X$  control = "job_entry"
X$  type = "DISPLAY_ENTRY"
X$  cnt = 0
X$INACC_LOOP:
X$ in_item = f$element(cnt,semi,inaccessible_list)
X$ if in_item.eqs.semi then $ goto EXIT
X$ `009cnt = cnt+1
X$`009if in_item.eqs.null then $ goto INACC_LOOP
X$`009job_queue_name = f$element(0,comma,in_item)
X$`009job_entry = f$element(1,comma,in_item)
X$`009call INFO_GET
X$`009call INFO_DISPLAY
X$ `009goto INACC_LOOP
X$ endif ! inaccessible_list
X$EXIT:
X$ if save_privs.nes.null then $ temp = f$setprv(save_privs)
X$ delsym = "call DELSYM "
X$ delsym job_inaccessible
X$ delsym job_pid
X$ delsym job_submit_time
X$ delsym job_user
X$ delsym job_name
X$ delsym job_cputime
X$ delsym job_login_time
X$ temp = f$ver(vfl)
X$ exit ! QUI_EXAMPLE
$ GoSub Convert_File
$ Exit
============================= End of Text to Cut =============================


-----------------------------------------------------------------
 Bob Boyd                     Usenet:    rlb@rtpark.ge.com
 GE Microelectronics Ctr.     Internet:  rlb%rtpark.ge.com@mcnc           
 POB 13049, MS 7T3-01         BitNet:    rlb%rtpark.ge.com@relay.cs.net
 RTP, NC 27709-3049           Voice:     (919)549-3627 
 GE DECnet: RTPARK::RLB       GE DIALCOMM:  8*565-3627  PROFS: SSAVRNA,MECRLBT
