.st0{fill:#FFFFFF;}

How to capture IBM-i job info for submitted jobs 

 October 2, 2019

By  NickLitten

Submitting jobs from within IBM i Control Language programs is a doddle. 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 – 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

NickLitten


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"cff50":{"name":"Main Accent","parent":-1},"a344d":{"name":"Accent Transparent","parent":"cff50"}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"cff50":{"val":"var(--tcb-skin-color-0)"},"a344d":{"val":"rgba(46, 138, 229, 0.85)","hsl_parent_dependency":{"h":210,"l":0.54,"s":0.78}}},"gradients":[]},"original":{"colors":{"cff50":{"val":"rgb(0, 178, 255)","hsl":{"h":198,"s":1,"l":0.5}},"a344d":{"val":"rgba(0, 178, 255, 0.85)","hsl_parent_dependency":{"h":198,"s":1,"l":0.5}}},"gradients":[]}}]}__CONFIG_colors_palette__

Get In Touch

Iā€™m always looking for awesome input, feedback and critique!

>