Midrange News for the IBM i Community


Posted by: Bob Cozzi
Rogue Programmer
Cozzi Productions, Inc.
Chicagoland
RPG Report 2012
has no ratings.
Published: 07 Feb 2012
Revised: 30 Sep 2014 - 2921 days ago
Last viewed on: 22 Sep 2022 (3295 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

RPG Report - 7 Feb 2012 Published by: Bob Cozzi on 07 Feb 2012 view comments

© Robert Cozzi, Jr. All rights reserved. Reproduction/Redistribution prohibited.
A midrangeNews.com Publication

Send Program Message Function in RPG IV

A Simple RPG IV Wrapper for the Send Program Message API

About 28 years ago I came out with "Cozzi Utilities" a set of CL Commands for the IBM System/38 whose CPF operating system was the forerunning to the contemporary IBM i OS we used today. Many of you already know that as time passed and I got burned out on writing free utilities, and focused on writing and doing seminars and User Group events. It was then that IBM started building end-user utilities to include with CPF and then OS/400. Many were overlapping with what I had already written, but you have to consider that there is a high-level of obviousness to Programmer Tools, so overlap is to be expected. The IBM package was known as QUSRTOOLS and were authored by a small group of IBMers led by CPF legend Jim Sloan, now of Jim Sloan, Inc. Upon retiring from IBM, Sloan started the aforementioned Jim Sloan, Inc. and took with him the rights to the library of QUSRTOOLS and turned it in the hugely successful TAATOOLS product, still available today.

What Does IBM i Have Today?

Today IBM i includes a lot of features that (A) were included with the original set of Cozzi Utilities and QUSRTOOLS, and (B) exposed via an API so "SPOOL File Processing" is no longer considered viable or necesary. In other words, much of what we wrote back then is now shipped with the IBM i operating system.

However, since 2010 I've gone back into Consulting and started building applications for clients. While in general I've focused on Web/Browser-based user interfaces and RPG IV with subprocedures, I have had clients that continue to want Green Screen applications. I had to learn Subfiles all over again as until recently it has literally been more than a decade since I last wrote one.

Sponsored by: BCD Software
Ad

To that end, I'm finding that there are still several ease-of-use features missing from the system. While some are classified as missing CL Commands, most are generally missing RPG IV-compatible subprocedure interfaces to APIs or algorithms. Until recently even the C runtime library was not available as RPG IV syntax prototypes unless you downloaded them from my website. Today many of them are included in QSYSINC. 

The QSYSINC library is really tailored towards C programmers. While there is an obvious half-hearted attempt to "shut up" the RPG programmers, largely QSYSINC is a necessary waste of space. I always recommend installing it on your system because there are some interfaces that work well, and you can always read the C structures and manually translate them into contemporary RPG IV syntax. The RPG IV shipped with QSYSINC is stuff converted from C using some type of "I don't know RPG IV and I think everyone still uses RPGIII" translator or badly written. The only exceptions, again, are the IFS interfaces and some C runtime functions recently provided.

 About 8 years ago I introduced a software packaged called "RPG xTools" which is in use in a rather large number of IBM i shops world-wide. It started out as an attempt to provide advanced RPG IV features to RPG IV programmers; effectively extending the RPG IV language. The nice thing is, even through we introduced RPG xTools in OS/400 v4r2 every one of the interfaces still works perfectly on IBM i v7r1 today.

When IBM pulled the plug on the popular CGIDEV service program for RPG IV CGI programming, we built a contemporary CGI library (aptly named "CGILIB") into RPG xTools, using RPG xTools. Today that CGI library powers the MidrangeNews.com website along with countless end-user shops' websites hosted on IBM i.

RPG Open 2012

No this isn't a golf outing; RPG Open is a free runtime library (actually a *SRVPGM) that I built and have been adding to over the years. The design objective was to provide a free runtime library of subprocedures that did things for the RPG IV Programmer--things that should already be in the language, but are not. For example converting between upper/lower case, scanning while ignoring case, extended math functions, min/max, and more. You can download the current version at www.RPGOpen.com it is free and no registration is required.

But like the free Cozzi Utilities of nearly 30 years ago, RPG Open has stalled. I put a lot of effort into the commercial RPG xTools product, but little effort goes into RPG Open. The standards of both are similar, albeit that RPG xTools has a "never blows up" design requirement while RPG Open has more of a "never blows up from its own coding" design. A subtle but important difference.

For RPG Open 2012 and beyond, I have produced a new packaging and a few new functions, more will be added as time passes. The new RPG Open 2012 will be provided in object code at v5r4 level. Each new release with be for a specific release of the operating system. For example, if we need to use a feature in v7r1, then RPG Open for v7.1 will be released and be upwardly compatible with prior versions. Any updates to the existing version will be published in all subsequent versions. This means if, for example as we are doing today, introducing a new subproceure in RPG Open for v5.4, it will also be available in the RPG Open for v7.1 package.

RPG Open "Check for Updates"

Using the new FTPFILE CL command included with RPG Open, you can run the CHKFORUPD CL command to see if your version of RPG Open on your IBM i level is current. Any updates to that level can be optionally downloaded and installed for no charge. PC's and Mac's have had this feature for years, its about time IBM i software offered it. The command includes an OPTION parameter that accepts, *DOWNLOAD, *NOTIFY, *AUTOINSTALL values. They are fairly self-explanatory.

SndMsgID and SndStsMsg Subprocedures

We extracted the code behind the RPG xTools' SNDMSGID subprocedure and created an RPG Open implementation. This version is somewhat simplified but allows you to send any type of message from QCPFMSG. A wrapper for the SNDMSGID subprocedure is SNDSTSMSG (Send status message) that sends a *STATUS message to *EXT from within RPG IV. Status messages were the most requested type of message to be sent from RPG IV, now its as easy as SndStsMsg('This program is running...');

Other message types may be issued using the SNDMSGID subprocedure, including INFO, DIAG, etc.

RPG Open Availability

RPG Open 2012 for v5.4 and later will be available by March 1st 2012 as a free download from www.RPGOpen.com

With this release, RPG Open will move to the same pricing model as I have done with iSockets and other software for IBM i. The object and source code for RPG Open for v5.4 will be available at no-charge. This version will continue to be available on the RPGOpen.com website as a free download.

Beyond v5.4 there is a per version charge of $295 (US) per system. This includes the object and source code for the specific version and the CHKFORUPD command to automatically download and install updates for RPG Open. So ask your Manager to budget the $295/year for RPG Open, your company will save more than that on its first use.

The source code for the SNDMSGID nad SNDSTSMSG subprocedures is included below. They are currently in final test and will be included in the March 1st release of RPG Open for v5

.....H NOMAIN BNDDIR('QC2LE') OPTION(*SRCSTMT:*NODEBUGIO)
      /INCLUDE rpgopen/QCPYSRC,copyright
      **  ---------------------------------------------- **
      **    (c) Copyright 2003-2012 by Robert Cozzi, Jr.
      **  ---------------------------------------------- **

      /INCLUDE rpgopen/QCPYSRC,apiprotos
      /INCLUDE rpgopen/QCPYSRC,msg


     P SndMsgID        B                   Export
      *******************************************
      **  Send a program message to a message queue.
      *******************************************
     D SndMsgID        PI
     D  szMsgID                       7A   Const
     D  szMsgData                  1024A   Const
     D  nMsgDataLen                  10I 0 Const OPTIONS(*NOPASS )
     D  szMsgType                    10A   Const OPTIONS(*NOPASS )
     D  szToPgmQ                     10A   Const OPTIONS(*NOPASS )

     D msgf            DS            21
     D  MsgFile                      10A   Inz('QCPFMSG')
     D  MsgLib                       10A   Inz('*LIBL')
     D
     D msgType         S             10A   Inz('*STATUS')
     D toPgmQ          S             10A   Inz('*EXT')
     D msgData         S                   Like(szMsgData)
     D nDataLen        S             10I 0 Inz(0)
     D nRelInv         S             10I 0 Inz(0)
     D nIncInv         S             10I 0 Inz(1)
     D RtnMsgKey       S              4A
     D myAPIError      DS                  LikeDS(QUSEC) Inz(*LIKEDS)
      /FREE
           if (%Parms() >= 3);
              nDataLen = nMsgDataLen;
           endif;

           if (nDataLen > 0);
              msgData = %subst(szMsgData:1:nDataLen);
           else;
              msgData = %TrimR(szMsgData);
              nDataLen = %Len(%TrimR(szMsgData));
           endif;

           if %Parms() >= 4;
              msgType = szMsgType;
           endif;

               //  Copy the ToPgmQ, if specified.
           if %Parms() >= 5;
              toPgmQ = szToPgmQ;
           endif;

           Select;
               //  *SAME
           when toPgmQ = ' '
                  or toPgmQ = '*SAME'
                  or toPgmQ = '*';
              toPgmQ = '*';
              nRelInv = 0;
              nIncInv = 1;
              //  *PRV, *PRVPRC or *PRVPROC
           when toPgmQ = '*PRVPRC'
               or toPgmQ = '*PREVPRC'
               or toPgmQ = '*PRVPROC'
               or toPgmQ = '*PREVPROC'
               or toPgmQ = '*PRV'
               or toPgmQ = '*PREV';
           toPgmQ = '*';
           nRelInv = 1;
           nIncInv = 1;

              //  *PRVPGM
           When toPgmQ = '*PRVPGM'
               or toPgmQ = '*PREVPGM'
               or toPgmQ = '*PRVPROG'
               or toPgmQ = '*PREVPROG';
           toPgmQ = '*CTLBDY';
           nRelInv = 0;
           nIncInv = 1;
              //  *CTLBDY
           when toPgmQ = '*CTLBDY'
               or toPgmQ = '*BNDRY'
               or toPgmQ = '*BOUNDARY'
               or toPgmQ = '*CTRLBDY'
               or toPgmQ = '*CB';
           toPgmQ = '*CTLBDY';
           nIncInv = 2;
           //*  *EXT
           when toPgmQ = '*EXT';
           nRelInv = 0;
           //*  DFT(*SAME)
           OTHER;
           toPgmQ = '*';
           nIncInv = 2;
           endsl;


           //  Since we're a relative invocation, and we are
           //  one-level deep, we need to bump up the relative
           //  invocation by one or two levels.
           nRelInv = nRelInv + nIncInv;

           callp(e) QMHSNDPM(szMsgID   :
                             msgF      :
                             msgData   :
                             nDataLen  :
                             msgType   :
                             toPgmQ    :
                             nRelInv   :
                             rtnMsgKey :
                             myApiError);
           return;
      /END-FREE
     P SndMsgID        E


     P SndStsMsg       B                   Export
      *******************************************
      **  Send a status message to *EXT pgm queue.
      *******************************************
     D SndStsMsg       PI
     D  szMsgText                  1024A   Const Varying
      /free
           SndMsgID('CPF9897':szMsgText:%Len(szMsgText):'*STATUS':'*EXT');
      /end-free
     P SndStsMsg       E 

 

Call Me

Bob Cozzi has been providing the solutions to midrange problems since 1983. He is available for consulting/contract development or on-site RPG IV, SQL, and CGI/Web training. To contact Cozzi, send an email to: bob at rpgworld.com

You can subscribe to RPG Report (we call it "follow") by visiting the RPG Report page on midrangeNews.com and then click the FOLLOW link in the table of contents for that page. To unsubscribe, simply click that same link. You must be signed up and signed in to midrangeNews.com to start following RPG Report.

Follow Bob Cozzi on Twitter

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS