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

 July 12, 2017

By  NickLitten

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

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

Is there another way?

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


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Trekkie, 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.

Nick Litten

related posts:

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"cff50":{"name":"Main Accent","parent":-1},"a344d":{"name":"Accent Transparent","parent":"cff50"}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"cff50":{"val":"var(--tcb-skin-color-0)"},"a344d":{"val":"rgba(46, 138, 229, 0.85)","hsl_parent_dependency":{"h":210,"l":0.54,"s":0.78}}},"gradients":[]},"original":{"colors":{"cff50":{"val":"rgb(0, 178, 255)","hsl":{"h":198,"s":1,"l":0.5}},"a344d":{"val":"rgba(0, 178, 255, 0.85)","hsl_parent_dependency":{"h":198,"s":1,"l":0.5}}},"gradients":[]}}]}__CONFIG_colors_palette__

Get In Touch

I’m always looking for awesome input, feedback and critique!