• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Sending Escape Messages From RPG, Take 2

    May 10, 2016 Hey, Ted

    In Sending Escape Messages from RPG, your program defines the message data parameter as 80 bytes, but the IBM manual (Send Program Message (QMHSNDPM)) defines the parameter as char(*), with notes saying it can be up to 32767. I would like a variable longer than 80, but instead of coding 100 today, 120 next project, and so on, I’m wondering how I could code it better to take full advantage of the API.

    –Glenn

    The short answer is that you don’t have to code the length. Let the compiler figure it out for you. Here’s an illustration that may help.

    Let’s suppose you use message USR1001 as a general escape message in an application. This message tells which program canceled, tells where it canceled, and gives some idea of what went wrong.

    ADDMSGD    MSGID(USR1001) MSGF(USRMSG) +
                 MSG('Program &1 canceled. Statement=&2, status=&3.') +
                 SECLVL('See previous messages in the job log for more +
                 information.') SEV(40) +
                 FMT((*CHAR 10) (*UBIN 2) (*CHAR 5))
    

    Notice the FMT parameter in the Add Message Description (ADDMSGD) command. It defines three fields. The first step in using this message is to create a data structure that defines those same fields. You might want to put it in a copybook.

    dcl-ds  USR1001  qualified inz;
         Program       char(10);
         Statement     uns(5);
         Status        char(5);
    end-ds;
    

    • Load the program subfield from the program status data structure.
    • Load the statement subfield with any number, using a different number for each error you trap. This tells you where the program found an error.
    • Load the status subfield with an appropriate status code (e.g., the SQL state) if needed.

    Create another copybook for a QMHSNDPM prototype.

    dcl-pr  QMHSNDPM     extpgm('QMHSNDPM');
       MsgID              char(7)      const;
       MsgFile            char(20)     const;
       MsgDta             char(32767)  const   options(*varsize);
       MsgDtaLen          int(10)      const;
       MsgType            char(10)     const;
       MsgQ               char(10)     const;
       MsgQNbr            int(10)      const;
       MsgKey             char(4);
       ErrorDs                         likeds(ErrorDS);
    end-pr;
    

    As you pointed out, the message data parameter can be up to 32,767 bytes long. Adding OPTIONS(*VARSIZE) allows you to pass character variables of other sizes. This is part of the answer to your question.

    Now, to address the rest of your question, here’s a fragmented program with a call to QMHSNDPM.

           ctl-opt actgrp(*caller) option(*srcstmt: *nodebugio);
    
           /copy copybooks,psds
           /copy copybooks,qmhsndpm
           /copy copybooks,errords
           /copy copybooks,usr1001
    
           dcl-s  MsgKey        char(4);
    
           *inlr = *on;
    
           monitor;
              Msg01RMain ();
           on-error;
              USR1001.Statement = 99;
              USR1001.Status = '99999';
              ErrorDS.BytesProvided = *zero;
           endmon;
    
           if USR1001.Statement <> *zero;
              USR1001.Program = psds.procedure;
              ErrorDS.BytesProvided = *zero;
              qmhsndpm ('USR1001': 'USRMSG    *LIBL': USR1001: %size(USR1001):
                        '*ESCAPE': '*PGMBDY': 1: MsgKey: ErrorDS );
           endif;
    
           return;
    
           dcl-proc  Msg01RMain;
    
                 dcl-c  EOD_SQL        const('02000');
    
                 // some sql statement here
                 if SQLState > EOD_SQL;
                    USR1001.Statement = 10;
                    USR1001.Status    = SqlState;
                 endif;
            end-proc;
    

    Notice the fourth argument supplied to QMHSNDPM: %SIZE(USR1001). Never do anything the compiler can do for you.

    So, to sum it up:

    1. Create a data structure that corresponds to the fields of the message description. Pass this data structure to QMHSNDPM as the message data.
    2. In the prototype for QMHSNDPM, define the message data parameter with the maximum length of 32,767 and OPTIONS(*VARSIZE).
    3. Use the %SIZE function to pass the length of the data structure to QMHSNDPM.

    If you do these things, you should have no problem sending escape messages from RPG programs, and your concern about the size of the message data parameter becomes a non-issue.

    It’s great that you’re looking for an effective way to use QMHSNDPM. Messaging is a fundamental that every developer should work to master.

    RELATED STORY

    Sending Escape Messages from RPG

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    PERFSCAN

    Revolutionary Performance Management Software

    At Greymine, we recognize there is a void in the IT world for a dedicated performance management company and also for a performance management tool that’s modern, easy to use, and doesn’t cost an arm and a leg. That’s why we created PERFSCAN.

    PERFSCAN is designed to make your job easier. With revolutionary technology, an easy-to-read report and graphics engine, and real time monitoring, tasks that used to take days can now take minutes. This means you will know your system better and will be able to provide better service to your customers.

    OUR FEATURES

    PERFSCAN is full of robust features that don’t require you to take a three-day class in order to use the product effectively.

    Customizable Performance Reporting

    Whether you are troubleshooting a major system problem or simply creating a monthly report, PERFSCAN lets you select any combination of desired performance metrics (CPU, Disk, and Memory).

    User Defined Performance Guidelines

    No matter if you are a managed service provider managing complex systems in the cloud or a customer analyzing your on-premises solution, PERFSCAN gives you the flexibility to define all mission critical guidelines how they need to be.

    Understanding The Impact Of Change

    Tired of all the finger pointing when performance is suffering? PERFSCAN’s innovative What’s Changed and Period vs. Period analysis creates a culture of proof by correlating known environmental changes with system performance metrics.

    Comprehensive Executive Summary

    Creating performance graphs is easy. Understanding what they mean is another thing. With one mouse click, PERFSCAN includes an easy-to-understand executive summary for each core metric analyzed.

    Combined Real-Time Monitor And Performance Analysis Tool

    With PERFSCAN’s combined built in enterprise real-time monitor and historical performance analysis capability, you will always know how your mission-critical systems are performing.

    Cloud Performance Reporting Is Easy

    Managing performance for production systems in the cloud can be a black hole to many system administrators. The good news is PERFSCAN analyzes all core metrics regardless of the location. That’s why MSPs and customers love PERFSCAN.

    Detailed Job Analysis

    PERFSCAN shows detailed top job analysis for any desired period. All metrics are displayed in two ways: Traditional Report and Percentage Breakdown Pie Chart. This toggle capability instantly shows the jobs using the most system resources.

    Save Report Capability

    Your boss lost the report you gave to him on Friday. Now what do you do? With PERFSCAN’s save report capability, any report can be retrieved in a matter of seconds.

    Professional PDF Reporting With Branding

    Creating professional looking reports for your customers has never been easier with PERFSCAN. Branding for our partners and service provider customers is easy with PERFSCAN.

    Check it out at perfscan.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    COMMON:  2016 Annual Meeting & Expo, May 15 - 18, in New Orleans! Great Power Systems event!
    NGS :  Webinar: Realizing the Power of IBM i with NGS-IQ. May 11. RSVP now!
    Profound Logic Software:  'i on the Enterprise' Worldwide Virtual Event. June 8. Register Now!

    IBM To Sell Off Two-Thirds Of The Rochester Labs Jazzing Up IBM i In COMMON’s Quarter

    Leave a Reply Cancel reply

Volume 16, Number 11 -- May 10, 2016
THIS ISSUE SPONSORED BY:

ProData Computer Services
BCD Software
T.L. Ashford

Table of Contents

  • OLAP Aggregation Specification In DB2 For i 7.3
  • Sending Escape Messages From RPG, Take 2
  • When You Reach Your Break(ing) Point. . . Or Not

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Fortra Issues 20th State of IBM i Security Report
  • FNTS Launches Managed Services for Power Servers in IBM Cloud
  • Total LTO Shipped Capacity Up Slightly in 2022
  • Four Hundred Monitor, May 24
  • Update On Critical Security Vulnerability In PowerVM
  • Critical Security Vulnerability In PowerVM Hypervisor
  • IBM Power: Hosted On-Premises Or In The Cloud?
  • Guru: Watch Out For This Pitfall When Working With Integer Columns
  • As I See It: Bob-the-Bot
  • IBM i PTF Guide, Volume 25, Number 21

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2023 IT Jungle