July 12

0 comments

Write to joblog messages from RPGLE /FREE – easy code example using Qp0zLprintf

By NickLitten

July 12, 2017

RPG, code, example, FREE, freeformat, ILE, joblog, modernization, Qp0zLprintf, RPGLE, snippet

RPG CODE EXAMPLE – “Write to joblog” in RPG with Qp0zLprintf

Write to joblog lets us send messages from inside a running RPG program. It’s simple using one of IBM’s API’s – Qp0zLprintf

Qp0zLprintf() — Print Formatted Job Log Data
The Qp0zLprintf () function prints user data specified by format-string as an information message type to the job log. If a second parameter, argument-list, is provided, Qp0zLprintf () converts each entry in the argument-list and writes the entry to the job log according to the corresponding format specification in format-string.

IBM

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: nick@nicklitten.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; 
 return;
 

You can writejobLog all over the place and its useful for watching processes in real time…

If we want to write multiple lines into the joblog, 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.

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

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

>