• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • RPG Subprocedure Error-Handling with APIs

    July 11, 2012 Ted Holt

    In the May 2, 2012, edition of this august publication, I shared how Brian Rusch’s shop uses an API to forward escape messages up the call stack in CL programs. The Resend Escape Message (QMHRSNEM) API works just as well in RPG subprocedures. Here’s how it’s easily done.

    First, you need a prototype for QMHRSNEM, and you must define the first two parameters.

    D ResendEscapeMsg...
    D                 pr                  extpgm('QMHRSNEM')
    D   MessageKey                   4a   const
    D   ErrorCode                   10i 0 const
    

    You can define the remaining parameters if you want, but make sure you mark them OPTIONS(*NOPASS). If you like, place the prototype in a copybook source member.

    In your subprocedure, place the “meat” under a MONITOR operation. Place the call to QHMRSNEM in the corresponding ON-ERROR group, like this:

    D ResendEscapeMsg...
    D                 pr                  extpgm('QMHRSNEM')
    D   MessageKey                   4a   const
    D   ErrorCode                   10i 0 const
    
     * ====================================================================
     * xxxx - description and other documentation
     * ====================================================================
    P <xxxxxxxxxxxx>  b                   export
    D                 pi
     //////////////////////// D specs for parameters
     *** locals
     //////////////////////// D specs for local data
     /free
         monitor;
            ... do something
            ... do something else
         on-error;
            ResendEscapeMsg (*blanks: *zero);
         endmon;
         return;
     /end-free
    P                 e
    

    Notice the two arguments supplied to ResendEscapeMessage: blanks and zeros. You’ll never need any other values.

    The result is that the system catches any fatal error and sends it along to the calling procedure.

    I like the way this works. Give it a try.

    RELATED STORY

    CL Error-Handling With APIs



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Midrange Dynamics North America

    Accelerate Change & Integration on IBM i

    Good change management unites IBM i and open systems development for productive collaboration. Developers work with their preferred tools and IDEs. Ultimate version control and traceability mean fast bug fixes and less stress. Rollback to a stable version in seconds.

    Change management gives managers, operations teams, and auditors the visibility they need, and developers can focus on what they like best: building great applications.

    Learn More

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Maxava:  When disaster strikes, you're in control with Maxava HA Enterprise+
    looksoftware:  FREE Webcast: Leverage mobile technology with IBM i. EMEA: June 26, U.S.: June 27
    T.L. Ashford:  Barcode400 Labeling Software makes it easy to design and print labels in minutes

    IT Jungle Store Top Book Picks

    BACK IN STOCK: Easy Steps to Internet Programming for System i: List Price, $49.95

    The iSeries Express Web Implementer's Guide: List Price, $49.95
    The iSeries Pocket Database Guide: List Price, $59
    The iSeries Pocket SQL Guide: List Price, $59
    The iSeries Pocket WebFacing Primer: List Price, $39
    Migrating to WebSphere Express for iSeries: List Price, $49
    Getting Started with WebSphere Express for iSeries: List Price, $49
    The All-Everything Operating System: List Price, $35
    The Best Joomla! Tutorial Ever!: List Price, $19.95

    Tomcat 7 Support Added to mrc’s m-Power Dev Tool Windows On The (2012 And Cloudy) World

    Leave a Reply Cancel reply

Volume 12, Number 18 -- July 11, 2012
THIS ISSUE SPONSORED BY:

WorksRight Software
Help/Systems
Tembo Application Generation

Table of Contents

  • DB2 For i XMLTABLE, Part 2: Using Namespaces And IFS XML Files
  • RPG Subprocedure Error-Handling with APIs
  • Admin Alert: Making Run the Same Run the Same On IBM i Access 7.1 On Windows 7

Content archive

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

Recent Posts

  • To Comfort The Afflicted And Afflict The Comfortable
  • How FalconStor Is Reinventing Itself, And Why IBM Noticed
  • Guru: When Procedure Driven RPG Really Works
  • Vendors Fill In The Gaps With IBM’s New MFA Solution
  • IBM i PTF Guide, Volume 27, Number 27
  • With Power11, Power Systems “Go To Eleven”
  • With Subscription Price, IBM i P20 And P30 Tiers Get Bigger Bundles
  • Izzi Buys CNX, Eyes Valence Port To System Z
  • IBM i Shops “Attacking” Security Concerns, Study Shows
  • IBM i PTF Guide, Volume 27, Number 26

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