• 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
    Rocket Software

    Unlock the full potential of your data with Rocket Software. Our scalable solutions deliver AI-driven insights, seamless integration, and advanced compliance tools to transform your business. Discover how you can simplify data management, boost efficiency, and drive informed decisions.

    Learn more today.

    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

    • Meet The Next Gen Of IBMers Helping To Build IBM i
    • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
    • Will Independent IBM i Clouds Survive PowerVS?
    • Now, IBM Is Jacking Up Hardware Maintenance Prices
    • IBM i PTF Guide, Volume 27, Number 24
    • Big Blue Raises IBM i License Transfer Fees, Other Prices
    • Keep The IBM i Youth Movement Going With More Training, Better Tools
    • Remain Begins Migrating DevOps Tools To VS Code
    • IBM Readies LTO-10 Tape Drives And Libraries
    • IBM i PTF Guide, Volume 27, Number 23

    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