October 2

0 comments

How to capture IBM-i job info for submitted jobs

By NickLitten

October 2, 2019

SBMJOB

Submitting jobs from within IBM i Control Language programs is EASY.

But sometimes we want to know the job name, or job queue, that the job was submitted with.

This is easy to do in CL, and since my colleague John “who’s surname cant be mentioned or else it will give him an internet presence alerting the FBI, NSA and YAKUZA who are all hunting him for various crimes committing during the 80’s” Doe asked me how to do it – So, here is a quick and simple CL example:

RCVMSG Example for SBMJOB

PGM
                                                            
 DCL        VAR(&MSGDTA) TYPE(CHAR) LEN(100)
 DCL        VAR(&SBMJOB) TYPE(CHAR) LEN(10)                    
 DCL        VAR(&SBMJOBUSR) TYPE(CHAR) LEN(10)
 DCL        VAR(&SBMJOBNBR) TYPE(CHAR) LEN(6)                  
 DCL        VAR(&SBMJOBQ) TYPE(CHAR) LEN(10)
 DCL        VAR(&SBMJOBQLB) TYPE(CHAR) LEN(10)                 
 
 SBMJOB     CMD(DLYJOB DLY(1)) JOB(SOMETHING) /* submit a silly job that will do nothing */               
 
 RCVMSG     PGMQ(SAME) MSGQ(PGMQ) MSGTYPE(COMP) RMV(NO) MSGDTA(&MSGDTA) /* retrieve last message from msg queue stack */                              
 
 CHGVAR     VAR(&SBMJOB) VALUE(%SST(&MSGDTA 1 10))              
 CHGVAR     VAR(&SBMJOBUSR) VALUE(%SST(&MSGDTA 11 10))          
 CHGVAR     VAR(&SBMJOBNBR) VALUE(%SST(&MSGDTA 21 6))           
 CHGVAR     VAR(&SBMJOBQ) VALUE(%SST(&MSGDTA 27 10))            
 CHGVAR     VAR(&SBMJOBQLB) VALUE(%SST(&MSGDTA 37 10))          
 
 RTVJOBA    JOB(&SBMJOB) USER(&SBMJOBUSR) NBR(&SBMJOBNBR)
 MONMSG     MSGID(CPF0000) EXEC(DO)                      
   SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('ERROR 
              Unable to find submitted job' *BCAT +      
              &SBMJOBNBR *TCAT '/' *TCAT &SBMJOBUSR +    
              *TCAT '/' *TCAT &SBMJOB *TCAT ')') +       
              TOPGMQ(PRV) MSGTYPE(COMP)                
   RETURN     /* add any error hnadlign routines here */   
 ENDDO                                                   

 SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) +                      
              MSGDTA('Submitted job was' *BCAT +                
              &SBMJOBNBR *TCAT '/' *TCAT &SBMJOBUSR +           
               *TCAT '/' *TCAT &SBMJOB *TCAT ', and it +  
               submitted using jobq(' *TCAT &SBMJOBQLB +  
               *TCAT '/' *TCAT &SBMJOBQ *TCAT ')') +      
               TOPGMQ(PRV) MSGTYPE(COMP)                
 ENDPGM                   

So, when we run this little program it submits a job (that does nothing other than delay for 1 second before gracefully ending) and then reads the last program message so it can snag the job details.

Then it just sends a program message with those details to our screen.

How to capture IBM-i job info for submitted jobs 1
Look Ma, I submitted something

Simples

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips

>