Write to joblog messages from RPGLE – easy code example

IBM i

Oct 28

RPG CODE EXAMPLE – “Write to joblog”

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

H OPTION(*SRCSTMT) DFTACTGRP(*NO)
D writeJobLog PR 10I 0 ExtProc('Qp0zLprintf')
D logMsg * Value OPTIONS(*STRING)
D s1 * Value OPTIONS(*STRING:*NOPASS)
D s2 * Value OPTIONS(*STRING:*NOPASS)
D s3 * Value OPTIONS(*STRING:*NOPASS)
D s4 * Value OPTIONS(*STRING:*NOPASS)
D s5 * Value OPTIONS(*STRING:*NOPASS)
D s6 * Value OPTIONS(*STRING:*NOPASS)
D s7 * Value OPTIONS(*STRING:*NOPASS)
D s8 * Value OPTIONS(*STRING:*NOPASS)
D s9 * Value OPTIONS(*STRING:*NOPASS)
D s10 * Value OPTIONS(*STRING:*NOPASS)

once you have defined this you can just use the writeJobLog opcode in your mainline:

writeJobLog ( 'Invalid Customer Number %s %s' : '1234' : 'ABC Customer' );
writeJobLog (X'25');  // EBCDIC code for carriage return

So – that’s a simple code example using older style RPG.

NOTE: I must come back and update this blog later.

ANOTHER NOTE: I just did come back and update it into RPG4 /FREE

 

Follow

About the Author

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.