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:
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 */ RRCVMSG 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.
IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Alpha Nerd 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 in the words of the most interesting man in the world: Stay thirsty my friend.
How to Upload a SAVF with IBM I ACS a.k.a. Upgrade HTTPAPI (LIBHTTP) to V7.2
Using RPGLE to extract invoice numbers from an alpha string
How do we Check for Batch or Interactive in CLLE
Second Look: IBM RDi Extract Procedure Refactoring feature
Rational Developer for IBM i 9.6 Fixpack 7 is pretty pretty good
Grabbing a library description in RPG with SQL
New Developerworks RDi website is ‘IBM Rational Developer for i Hub’
Developerworks Connections Sunset – How to Extend RDi
Why use IBM i RDi?