IBM i create JOBLOG from RPGLE /FREE – a QMHSNDPM code example

AS400

Jul 12

RPG CODE EXAMPLE – “Write to joblog” in Free Format RPGLE

Write to the IBM i joblog is a neat way of recording details of any running jobs information.

This example lets us send messages from inside a running RPG program.

It’s simple using one of IBM’s API’s – QMHSNDPM – and this source code example if a very simple view of modern RPGLE code in action.

RPGLE Code Example using QMHSNDPM

// SNDMSGLOG1.RPGLE
// Simple Program to send message to joblog using QMHSNDPM
// Author: nick@nicklitten.com

ctl-opt dftactgrp(*no) actgrp('NICKLITTEN')
 option(*nodebugio:*srcstmt:*nounref)
 alwnull(*inputonly)
 datfmt(*ISO) decedit('0.')
 copyright('SNDMSGLOG1 | V1.0.0 2017.06.25 | Playing with messages');

dcl-pr writeJobLog extpgm('QMHSNDPM');
 *n char(7) const; // MsgID
 *n char(20) const; // MsgFile
 *n char(32767) const options(*varsize); // MsgData
 *n int(10) const; // MsgDtaLen
 *n char(10) const; // MsgType
 *n char(10) const; // StackEntry
 *n int(10) const; // StackCount
 *n char(4); // MsgKey
 *n char(32767) options(*varsize); // ErrorCode
 end-pr;

dcl-ds ErrorCode;
 BytesProv int(10) inz(0);
 BytesAvail int(10) inz(0);
end-ds;

dcl-s Msg char(200);
dcl-s MsgKey char(4);

Msg = '* Another test message. Lorem Ipsum Pussycat.';

// note 2nd parm is a 20 char field with "file___*lib" 
writeJobLog('CPF9897'
           :'QCPFMSG *LIBL'      
           :Msg
           :%len( %trimr(Msg))
           :'*DIAG'
           :'*'
           :0
           :MsgKey
           :ErrorCode
           );

*INLR = *on;

This is a follow up to this simpler example and it just goes to show there are many different ways to swing the exact same cat.

The added benefit of this code example is that we can choose the message type *COMP, *DIAG, *INFO etc etc

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.