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

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

NickLitten


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad 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 remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

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

Start your
7-day free trial

Take This Course with ALL ACCESS

Unlock your Learning Potential with instant access to every course and all new courses as they are released.
 [ For Serious Software Developers only ]

IBM i Training For Technology Experts

New!

Successfully Work Remote 

 $ 129.00  $59.00

By adding new skills in information technology, employers will be confident that you have the necessary skills and tools needed to successfully work remotely

>

Snug CBD

 20% Discount

I have partnered with SNUG CBD givING you Organic CBD
20% discount code "NL20"