July 12

0 comments

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

By NickLitten

July 12, 2017

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

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

WAIT – There is another way which is a bit cleaner!

Yup. It’s even simpler using the qp0zlprintf IBM *API. Check it out here

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

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

>