• 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

    Want to deliver DevOps on IBM i?

    DevOps enables your IBM i development teams to shorten the software development lifecycle while delivering features, fixes, and frequent updates that are closely aligned with business objectives. Flexible configuration options within MDChange make it easy to adapt to new workflow strategies and policies as you adopt DevOps practices across your organization.

    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

  • Positive News From The Kyndryl Mainframe Modernization Report
  • NAViGATE, inPower 2025 On Tap for September 2025
  • Guru: WCA4i And Granite – Because You’ve Got Bigger Things To Build
  • As I See It: Digital Coup
  • IBM i PTF Guide, Volume 27, Number 37
  • AI Is Coming for ERP. How Will IBM i Respond?
  • The Power And Storage Price Wiggling Continues – Again
  • LaserVault Adds Multi-Path Support To ViTL
  • As I See It: Spacing Out
  • IBM i PTF Guide, Volume 27, Numbers 34, 35, And 36

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