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

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

July 12, 2017

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

// Simple Program to send message to joblog using QMHSNDPM
// Author:

ctl-opt dftactgrp(*no) actgrp('NICKLITTEN')
 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

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

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" 
           :'QCPFMSG   *LIBL'      
           :%len( %trimr(Msg))

*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