fhg
Volume 12, Number 18 -- July 11, 2012

RPG Subprocedure Error-Handling with APIs

Published: July 11, 2012

by 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


Sponsored By
HELP/SYSTEMS

IBM i Scheduling Survival Guide

Introducing scheduling automation into your operations environment
can have as many downsides as benefits, if not done right.

This guide walks you through the research and planning phases and provides
a helpful rollout checklist. With over 30 years of experience helping
customers automate their IBM i environments, Help/Systems
offers the insight you need to succeed.

Download the guide free.


Senior Technical Editor: Ted Holt
Technical Editor: Joe Hertvik
Contributing Technical Editors: Edwin Earley, Brian Kelly, Michael Sansoterra
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

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


 
The Four Hundred
Some Insight Into Those Future Power7+ Processors

Help/Systems Buys Safestone To Boost Power Systems Security

IBM i Marketing Plans Get The iManifest Touch

As I See It: The Visionary

IBM Goes BYOD With VDI

Four Hundred Stuff
Krengel Challenges Shops to Keep UPS Shipping Apps on IBM i

New Orleans Company Applies Katrina's Lessons to New DR Strategy

ProData Updates DBU and Deleted File Retriever

Kisco Refines IBM i Database Auditing Tool

Synergivity Developing New Menu System

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

System i PTF Guide
July 7, 2012: Volume 14, Number 27

June 30, 2012: Volume 14, Number 26

June 23, 2012: Volume 14, Number 25

June 16, 2012: Volume 14, Number 24

June 9, 2012: Volume 14, Number 23

June 2, 2012: Volume 14, Number 22

TPM at The Register
Dell finally nabs Quest for $2.4bn

Finland beefs up HPC oomph with Cray 'Cascade' super

Boston flexes its own ARM server muscle

July 6, 2012: Informatica caught flat-footed by revenue shortfall

July 6, 2012: IT pulls its job creation weight in June in the US

July 5, 2012: Rutherford Appleton Lab fires up ceepie-geepie hybrid

Calxeda ramping up ARM server boards

Global players wolfing down chips again after crap Q1

IBM snuggles up BigInsights Hadoop with Cloudera

Super Micro fattens up Xeon E5 nodes with FatTwins

VMware snatches cloud-furtling biz from the very jaws of Dell

More revelers amp up hybrid memory cube party

THIS ISSUE SPONSORED BY:

WorksRight Software
Help/Systems
Tembo Application Generation


Printer Friendly Version


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

Four Hundred Guru

BACK ISSUES




 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2012 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement