• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Using APIs to Send Impromptu Messages

    October 9, 2002 Ted Holt

    Hey, Ted:

    I would like to use the error message APIs QMHRMVPM and QMHSNDPM in an RPG IV program to send messages to an error-message subfile.

    I do not want to have to define the messages in a message file. I would prefer to use constant definitions from within my RPG program. Is this possible?

    I’ve searched written manuals and have not yet found a way to do this.

    — Russell

    Any message that is not sent as an *ESCAPE, *STATUS, or *NOTIFY message can be sent as an impromptu message, Russell. Here’s a short program you can play with. The display file is the JKL001D file from the March 29, 2002, “Odds and Ends” column.

    A                                      DSPSIZ(24 80 *DS3)
    A          R FORMAT01
    A                                      CA03(03)
    A                                      OVERLAY
    A                                  1 31'Generate Some Report'
    A                                  1 72DATE
    A                                      EDTCDE(Y)
    A                                  2 72TIME
    A                                  5  8'Enter range of dates in MMDDYY for-
    A                                      mat. You may leave ending date'
    A                                  6  8'blank if the report is to be run f-
    A                                      or only one day.'
    A                                  8  8'Beginning date ...................-
    A                                      ...........:'
    A            SBGNDATE       6Y 0B  8 55EDTCDE(4)
    A                                  9  8'Ending date ......................-
    A                                      ...........:'
    A            SENDDATE       6Y 0B  9 55EDTCDE(4)
    A                                 22  6'F3=Cancel request'
    A                                 22 27'Enter=Generate report'
    A
    A          R MSGSFL                    SFL
    A                                      SFLMSGRCD(24)
    A            MSGKEY                    SFLMSGKEY
    A            PGMNAM                    SFLPGMQ
    A
    A          R MSGCTL                    SFLCTL(MSGSFL)
    A                                      SFLSIZ(0010)
    A                                      SFLPAG(0001)
    A                                      OVERLAY
    A                                      SFLDSP
    A                                      SFLDSPCTL
    A                                      SFLINZ
    A N87                                  SFLEND
    A            PGMNAM                    SFLPGMQ(10)
    

    Notice the SFLPGMQ keywords in both the subfile and subfile control formats. I attached the field name PGMNAM to both of them. (This is a habit from my RPG III days, when the maximum allowable length of variable names was six characters.) This variable gets its value from the program status data structure of the RPG program.

    Here’s the RPG source code. I compiled it with Create Bound RPG Program (CRTBNDRPG) command to run in the default activation group. I only included one test for an error. In a production environment, there would be more, of course.

    FJKL001D   cf   e             workstn
    
    D Error           s               n
    
    D ErrorDS         ds            16
    D   BytesProv                   10i 0 inz(%size(ErrorDS))
    D   BytesAvail                  10i 0
    D   ExceptionID                  7
    
    D                sds
    D  PgmNam           *proc
    D
    D Msg             s             78
    D
    D SendMsg         pr                  extpgm('QMHSNDPM')
    D   MsgID                        7a   const
    D   MsgF                        20a   const
    D   MsgData                     30a   const
    D   MsgDataLen                  10i 0 const
    D   MsgType                     10a   const
    D   CallStackEnt                10a   const
    D   CallStackCtr                10i 0 const
    D   MsgKey                       4a   const
    D   Error                             like(ErrorDS)
    
    D ClrMsgQ         pr                  extpgm('QMHRMVPM')
    D   MsgQueue                   276a   const
    D   CallStack                   10i 0 const
    D   MsgKey                       4a   const
    D   MsgRmv                      10a   const
    D   Error                             like(ErrorDS)
    
     /free
       dow '0' = '0';
         exfmt format01;
         // clear msg subfile
         callp  ClrMsgQ ('*': *zero: *blanks: '*ALL': ErrorDS);
         if *in03;
            leave;
         endif;
         // ++++++++ calcs to verify data go here ++++++++
         error = *off;
         if (sbgndate = *zero);
            error = *on;
            msg = 'Beginning date must not be blank.';
         endif;
         // ----------------------------------------------
         if not error;
            leave;
         endif;
         callp  SendMsg (*blanks: *blanks :
                Msg : %size(Msg):
                '*INFO': '*':
                 0: *blanks: ErrorDS);
         write msgctl;
       enddo;
    
      if not *in03;
        // do what needs to be done
      endif;
    
      *inlr = *on;
     /end-free
    

    I hope this helps.

    — Ted

    Sponsored By
    inFORM DECISIONS

    ELIMINATE THE COSTS OF PRE-PRINTED FORMS, LABOR AND POSTAGE WITH
    inFORM Decisions iDocs™ ‘Suite’

    iSeries based e-Forms, e-Checks, e-Mail, e-FAX, and Document Retrieval from the Web are available as individual modules or as a complete e-Document processing ‘Suite’.

    Click to Download the Complete Suite or Individual Modules today
    www.inFORMDecisions.com

    or call (800) 858-5544

     

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: 2002, mgo_rc, Number 77 -- October 9, Volume 2

    Sponsored by
    DRV Tech

    Get More Out of Your IBM i

    With soaring costs, operational data is more critical than ever. IBM shops need faster, easier ways to distribute IBM applications-based data to users more efficiently, no matter where they are.

    The Problem:

    For Users, IBM Data Can Be Difficult to Get To

    IBM Applications generate reports as spooled files, originally designed to be printed. Often those reports are packed together with so much data it makes them difficult to read. Add to that hardcopy is a pain to distribute. User-friendly formats like Excel and PDF are better, offering sorting, searching, and easy portability but getting IBM reports into these formats can be tricky without the right tools.

    The Solution:

    IBM i Reports can easily be converted to easy to read and share formats like Excel and PDF and Delivered by Email

    Converting IBM i, iSeries, and AS400 reports into Excel and PDF is now a lot easier with SpoolFlex software by DRV Tech.  If you or your users are still doing this manually, think how much time is wasted dragging and reformatting to make a report readable. How much time would be saved if they were automatically formatted correctly and delivered to one or multiple recipients.

    SpoolFlex converts spooled files to Excel and PDF, automatically emailing them, and saving copies to network shared folders. SpoolFlex converts complex reports to Excel, removing unwanted headers, splitting large reports out for individual recipients, and delivering to users whether they are at the office or working from home.

    Watch our 2-minute video and see DRV’s powerful SpoolFlex software can solve your file conversion challenges.

    Watch Video

    DRV Tech

    www.drvtech.com

    866.378.3366

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    David’s Choice for Java Error Logging Reader Feedback and Insights: Dynamic Result Field in Query/400

    Leave a Reply Cancel reply

MGO Volume: 2 Issue: 77

This Issue Sponsored By

    Table of Contents

    • Reader Feedback and Insights: QTEMP and the Library List
    • FTP and Save Files, Yet Again!
    • Using APIs to Send Impromptu Messages

    Content archive

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

    Recent Posts

    • The Power11 Transistor Count Discrepancies Explained – Sort Of
    • Is Your IBM i HA/DR Actually Tested – Or Just Installed?
    • Big Blue Delivers IBM i Customer Requests In ACS Update
    • New DbToo SDK Hooks RPG And Db2 For i To External Services
    • IBM i PTF Guide, Volume 27, Number 33
    • Tool Aims To Streamline Git Integration For Old School IBM i Devs
    • IBM To Add Full System Replication And FlashCopy To PowerHA
    • Guru: Decoding Base64 ASCII
    • The Price Tweaking Continues For Power Systems
    • IBM i PTF Guide, Volume 27, Numbers 31 And 32

    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 © 2025 IT Jungle