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

    Embrace VS Code for IBM i Development

    The IBM i development landscape is evolving with modern tools that enhance efficiency and collaboration. Ready to make the move to VS Code for IBM i?

    Watch this webinar where we showcase how VS Code can serve as a powerful editor for native IBM i code and explore the essential extensions that make it possible.

    In this session, you’ll discover:

    • How ARCAD’s integration with VS Code provides deep metadata insights, allowing developers to assess the impact of their changes upfront.
    • The role of Git in enabling seamless collaboration between developers using tools like SEU, RDi, and VS Code.
    • Powerful extensions for code quality, security, impact analysis, smart build, and automated RPG conversion to Free Form.
    • How non-IBM i developers can now contribute to IBM i projects without prior knowledge of its specifics, while ensuring full control over their changes.

    The future of IBM i development is here. Let ARCAD be your guide!

    Watch the replay now!

    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

    • POWERUp 2025 –Your Source For IBM i 7.6 Information
    • Maxava Consulting Services Does More Than HA/DR Project Management – A Lot More
    • Guru: Creating An SQL Stored Procedure That Returns A Result Set
    • As I See It: At Any Cost
    • IBM i PTF Guide, Volume 27, Number 19
    • IBM Unveils Manzan, A New Open Source Event Monitor For IBM i
    • Say Goodbye To Downtime: Update Your Database Without Taking Your Business Offline
    • i-Rays Brings Observability To IBM i Performance Problems
    • Another Non-TR “Technology Refresh” Happens With IBM i TR6
    • IBM i PTF Guide, Volume 27, Number 18

    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