Accessing any job's QTEMP

There have been numerous requests from programmers who want to access and manipulate with a job's QTEMP library. It is used for debugging and/or recovering from a job that has fallen over with a MSGW status. On occasion, the remedy would involve either investigating the contents in QTEMP or modifying the contents in it. Or the error may be also caused by an incorrect library list. The program may attempt to access objects that do not exist due to a missing library in the library list. Whichever the case, it is especially useful if we could remotely execute commands on a job as if it was the job itself that issued the command. Once the problem has been rectified, such as the missing library list scenario, then instead of answering "c" to cancel the request, you now answer "r" to retry the operation.

There have been earlier approaches to execute commands on another session that uses the message queue concept. It places the workstation message queue into *BREAK delivery mode and uses a break-handling program. When a message is received, the break handling program takes over and executes the command contained in the message. The problem with this approach is that it will not work with batch jobs. You cannot send messages to a batch job from another job. Moreover, the user profile also needs to be setup to run an initial program that will place the workstation message queue into break delivery mode. This approach is cumbersome and of limited use with only interactive jobs.

Finally there is a way to run commands on any job, batch or online and without any cumbersome pre-requisites. It consists of three parts, a command (RUNJOBCMD), a command processing program (SNDCMDCL) and an exit program (RCVCMDCL).

For this to work, you must have the following:

1. *USE authority to the user profile where the command is intended to be executed.

2. *USE authority to STRSRVJOB, ENDSRVJOB and TRCJOB commands. These commands are normally shipped with *EXCLUDE authority.

3. Or have *SERVICE special authority in your user profile.

This is the RUNJOBCMD command. It accepts two main parameters, the iSeries 400 job (where the command will be executed) and a command to be executed. Note: The command will be executed under the job that is being specified. It does not run under your current sign on session.

/* Copyright 2002 David Ong (dsso@hotmail.com)                   */
/* Command.....: RUNJOBCMD                                       */
/* Description.: Runs a command on a job                         */
/*                  SRCFILE(YOURLIB/QCMDSRC)                     */
/*                                                               */
             CMD        PROMPT('Run job command')                  
             PARM       KWD(JOBNAME) TYPE(*CHAR) LEN(10) MIN(1) +  
                          CHOICE('Name') PROMPT('Job name')        
             PARM       KWD(JOBUSER) TYPE(*CHAR) LEN(10) MIN(1) +  
                          CHOICE('Name') PROMPT('Job user')        
             PARM       KWD(JOBNUMBER) TYPE(*CHAR) LEN(6) +        
                          RANGE('000000' '999999') MIN(1) +        
                          CHOICE('000000 - 999999') PROMPT('Job +  
             PARM       KWD(COMMAND) TYPE(*CHAR) LEN(512) MIN(1) + 
                          CHOICE('Name') PROMPT('Command to run')
C This is the SNDCMDCL program which is the CPP for RUNJOBCMD. It will interrupt the iSeries 400 job by starting a service request. Then sends the command to be executed via data queues. When the command finishes executing, the messages (if any) are returned and displayed to the user.

 /* Copyright 2002 David Ong (dsso@hotmail.com)                 */    
/* Program.....: SNDCMDCL                                      */    
/* Description.: CPP for RUNJOBCMD. Sends command to execute   */    
/*               via data queue.                               */    
/* Compile.....: CRTCLPGM PGM(QGPL/SNDCMDCL) +                 */    
/*                  SRCFILE(YOURLIB/QCLSRC)                    */    
/*                                                             */    
             PGM        PARM(&JOBNAME &USER &JOBNO &CMD)             
             DCL        VAR(&JOBNAME)  TYPE(*CHAR) LEN(10)           
             DCL        VAR(&USER)     TYPE(*CHAR) LEN(10)           
             DCL        VAR(&JOBNO)    TYPE(*CHAR) LEN(06)           
             DCL        VAR(&CMD)      TYPE(*CHAR) LEN(512)          
             DCL        VAR(&MSG)      TYPE(*CHAR) LEN(132)          
             DCL        VAR(&LEN)      TYPE(*DEC)  LEN(5 0) VALUE(80)
             DCL        VAR(&SNDDTAQ)  TYPE(*CHAR) LEN(10)           
             DCL        VAR(&RCVDTAQ)  TYPE(*CHAR) LEN(10)           
             DCL        VAR(&WAIT)     TYPE(*DEC)  LEN(5 0) VALUE(15)
             MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR))      
/* Creates data queue to send command and receive messages     */    
             CHGVAR     VAR(&SNDDTAQ)  VALUE('SND' || &JOBNO)        
             CHGVAR     VAR(&RCVDTAQ)  VALUE('RCV' || &JOBNO)        

             CHKOBJ     OBJ(&SNDDTAQ) OBJTYPE(*DTAQ)                  
             MONMSG     MSGID(CPF9801) EXEC(DO)                       
             CRTDTAQ    DTAQ(QGPL/&SNDDTAQ) MAXLEN(512) TEXT('Send +  
                          Command Data Queue')                        
             CRTDTAQ    DTAQ(QGPL/&RCVDTAQ) MAXLEN(512) TEXT('Status +
                          Data Queue')                                
/* Clear data queue just in case & sends the command to run      */   
             CALL       PGM(QCLRDTAQ) PARM(&SNDDTAQ 'QGPL')           
             CALL       PGM(QCLRDTAQ) PARM(&RCVDTAQ 'QGPL')           

/* Interrupts the job and executes the command                   */  
             STRSRVJOB  JOB(&JOBNO/&USER/&JOBNAME)                   
/* Wait for indication that the command has completed processing */  
             DLYJOB     DLY(2)                                       
             TRCJOB     SET(*END) MAXSTG(1024)                       
/* End servicing job and interrupt                               */  
/* Receive the completion messages                               */  
             CHGVAR     VAR(&WAIT) VALUE(0)                          
             IF         COND(&LEN *EQ 0) THEN(GOTO CMDLBL(CLEANUP))  
             SNDPGMMSG  MSG(&MSG)                                    
             CHGVAR     VAR(&MSG) VALUE(' ')                         
             GOTO       CMDLBL(RCVMSG)                               

/* Error occurred within this program, so just send error message*/
 ERROR:      RCVMSG     MSGTYPE(*EXCP) RMV(*NO) MSG(&MSG)          
             SNDPGMMSG  MSG(&MSG)                                  
 CLEANUP:    DLTDTAQ    DTAQ(QGPL/&SNDDTAQ)                        
             MONMSG     MSGID(CPF0000)                             
             DLTDTAQ    DTAQ(QGPL/&RCVDTAQ)                        
             MONMSG     MSGID(CPF0000)                             
 ENDIT:      ENDPGM        

This is the RCVCMDCL program. It is the exit program specified in the TRCJOB command. This program will run under the job being serviced. It accepts the commands to execute via data queues and returns the completion messages also through data queues.

/* Copyright 2002 David Ong (dsso@hotmail.com)                 */   
/* Program.....: RCVCMDCL                                      */   
/* Description.: Receives command from data queue and          */   
/*               excecutes it via QCMDEXC                      */   
/* Compile.....: CRTCLPGM PGM(QGPL/RCVCMDCL) +                 */   
/*                  SRCFILE(YOURLIB/QCLSRC)                    */   
/*                                                             */   
             PGM        PARM(&DUMMY)                                
             DCL        VAR(&DUMMY)    TYPE(*CHAR) LEN(100)         
             DCL        VAR(&JOBNO)    TYPE(*CHAR) LEN(06)          
             DCL        VAR(&CMD)      TYPE(*CHAR) LEN(512)         
             DCL        VAR(&MSG)      TYPE(*CHAR) LEN(132)         
             DCL        VAR(&CLEN)     TYPE(*DEC)  LEN(15 5)        
             DCL        VAR(&SNDDTAQ)  TYPE(*CHAR) LEN(10)          
             DCL        VAR(&RCVDTAQ)  TYPE(*CHAR) LEN(10)          
             DCL        VAR(&LEN)      TYPE(*DEC)  LEN(5 0)         
             DCL        VAR(&WAIT)     TYPE(*DEC)  LEN(5 0) VALUE(0)
             MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(ENDIT))     
             RTVJOBA    NBR(&JOBNO)                                 
             CHGVAR     VAR(&RCVDTAQ) VALUE('SND' || &JOBNO)        
             CHGVAR     VAR(&SNDDTAQ) VALUE('RCV' || &JOBNO)        

/* Receive command from data queue                             */     
/* Runs the command                                            */     
             IF         COND(&LEN *EQ 0) THEN(GOTO CMDLBL(ENDIT))     
             CHGVAR     VAR(&CLEN) VALUE(&LEN)                        
             CALL       PGM(QCMDEXC) PARM(&CMD &CLEN)                 
             MONMSG     MSGID(CPF0000)                                
/* Indicates command completion and sends completion messages  */     
             CHGVAR     VAR(&LEN) VALUE(1)                            
             RCVMSG     RMV(*NO) MSG(&MSG) MSGLEN(&LEN)               
             IF         COND(&MSG *NE ' ') THEN(GOTO CMDLBL(SENDMSG)) 
 ENDIT:      ENDPGM        

Here I provide a hypothetical example of displaying the contents of QTEMP for a batch job named GLPOST, running under userid DAVIDONG and the job number is 123456.


Because the command runs under Davidong's user profile, then you will need to work with Davidong's spool files to view the report.

This was first published in April 2002

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.