Write to joblog lets us send messages from inside a running RPG program. It’s simple using one of IBM’s API’s – Qp0zLprintf
I’ve used this little technique for ever. Simple define a procedure calling the API (in this example I call it “writejoblog”) and then in your mainline code you can just use the “writejoblog” command and squirt things into the joblog. I find this really useful when testing webservices, or anyh other batch processes, and cant be bothered to debug with a service job but just want to quickly write values to the joblog to trace what it’s upto.
RPGLE Code Example
// SNDMSGLOG.rpgle // Simple Program to send message to joblog using 'Qp0zLprintf' // Author: email@example.com ctl-opt dftactgrp(*no) actgrp('NICKLITTEN') option(*nodebugio:*srcstmt:*nounref) datfmt(*ISO) decedit('0.') copyright('SNDMSGLOG | V1.0.0 2017.06.25 | Playing with messages'); dcl-pr writeJobLog int(10) extproc('Qp0zLprintf'); *n pointer value options(*string); // logMsg *n pointer value options(*string:*nopass); *n pointer value options(*string:*nopass); *n pointer value options(*string:*nopass); *n pointer value options(*string:*nopass); *n pointer value options(*string:*nopass); *n pointer value options(*string:*nopass); *n pointer value options(*string:*nopass); *n pointer value options(*string:*nopass); *n pointer value options(*string:*nopass); *n pointer value options(*string:*nopass); end-pr; dcl-s joblogMSG varchar(200); dcl-c joblogCRLF const(x'0d25'); // My Preferred technique for writing joblog messages // NOTE: the first parm must contain a literal '%s' which I guess // tells IBM I to look at the next parm for a Carriage Return joblogMSG = '* Invalid Customer Number 1234 ABC CUSTOMER'; writeJobLog(joblogMSG+'%s':joblogCRLF); *inlr=*on;
You can writejobLog all over the place and its useful for watching processes in real time…
NOTE: We could program the API call in a slightly more verbose way:
// If you prefer to use each parm to construct your joblog // messages then you could do it like this, as long as you // remember to include a '%s' for each extra parm you are // including. I think this is a bit convoluted. writeJobLog('* Some other error about %s %s' :'1234' :'ABC Customer' ); writeJobLog(joblogCRLF); // EBCDIC code for carriage return
Don’t forget to stick the CRLF on the end… otherwise your IBM i joblog messages will start start overlapping.
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 refresh the Pitney Bowes CODE1 Address Database on IBM I without using FTP
RPG Divide and Move Remainder – DIV MVR in ILE RPGLE /FREE
RPG Evolution, Modernization and Refactoring – Step 5 of 4 – RPG FREE FORMAT 2017
Dirty RPG programmers need to write Clean RPG Code
Write to joblog messages from RPGLE /FREE – a QMHSNDPM code example
Write to joblog messages from RPGLE /FREE – easy code example using Qp0zLprintf
RPG example: store webservice reply XML or JSON in IFS
Write to joblog messages from RPGLE – easy code example
How to add the Turnover V100 Perspective to WDSC7