fhg
Volume 12, Number 26 -- October 31, 2012

Data Structures Make Good Status Parameters

Published: October 31, 2012

by Ted Holt

When a good program goes bad, someone must fix it. Sometimes that someone is me. As for the "when," it's never a good time. It's important to me that the failing program give me as much information as possible to help me pinpoint the cause of the error as quickly as possible.

There are two ways a program can inform its caller that it could not complete normally. One way is by sending a message. (I have written about this topic before; see the Related Stories at the end of this article.) The other way is to use a status parameter, also known as a "return code."

It is common for a program to place a zero into a status parameter if all went well, and a non-zero value if something went wrong. A good example of this convention is the SQL state.

I wrote earlier this year about an extension of the SQL state that identifies the statement that ended in error.

You can take this idea even further, making the program in error pass back as much data as you wish. I illustrate with an RPG data structure, but the technique works with any language.

First, create a message, like this:

crtmsgf *curlib/mymsgf
addmsgd msgid(MYM1101) msgf(*curlib/mymsgf) +
          msg('&2 errors were found in program &1.') +
          seclvl('Correct the errors and rerun.') +
          fmt((*char 10) (*bin 4))

The message has two positional parameters, which occupy 14 bytes of storage.

Now, define a compatible data structure in the program(s) that will trap for this error. Here's the structure in RPG.

D Status          ds           256    inz
D   MsgID                        7a
D   PgmName                     10a
D   ErrorCount                  10i 0

The first seven bytes are set aside for the message ID. The remaining subfields of the data structure match the definitions of the substitution values in the message description.

I've kept the structure simple. It tells me the name of the rogue program and the number of errors it found. The more information you put into the structure, the better, because a user can read a message to you over the telephone, but having someone read a program dump to you is impractical.

Loading the structure is easy.

     if ErrorCounter > *zero;
        MsgID = 'MYM1101';
        PgmName = ProcName;          // from the PSDS
        ErrorCount = ErrorCounter; 
        ouStatus = Status;
     endif;

The last line gives the data back to the caller, because ouStatus is the first parameter.

D OnePgm          pi
D  ouStatus                    256a
D  inWhs                         3a   const
D  inItem                       12a   const

The driver CL looks like this (without appropriate code to handle unexpected errors).

pgm parm(&inOption &inItem &inWhs)

   dcl  &inOption    *char    1
   dcl  &inItem      *char   12
   dcl  &inWhs       *char    3

   dcl  &Status      *char  256

   call OnePgm  (&Status &inWhs &inItem)

   if cond(%sst(&Status 1 7) *eq ' ') then( +
         call TwoPgm  (&Status &inOption))

   if cond(%sst(&Status 1 7) *eq ' ') then(+
         call RedPgm  (&Status))

   if cond(%sst(&Status 1 7) *eq ' ') then(+
         call BluePgm  (&Status &inWhs))

   if cond(%sst(&Status 1 7) *ne ' ') then( +
         sndpgmmsg   msgid(%sst(&Status 1 7)) msgf(MyMsgF) +
                        msgdta(%sst(&Status 8 249)) +
                        msgtype(*escape))

endpgm

If a program finds an error, the system ignores the subsequent program calls. If any program ends in error, the last IF makes the CL program shut down by sending an escape message similar to this one:

50 errors were found in program OnePgm.

I used this technique in a project I worked on recently, and was very pleased with the results. Data structures make tremendous status parameters.


RELATED STORIES

Sending Escape Messages from RPG

RPG Subprocedure Error-Handling with APIs

Error Checking and Embedded SQL



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


Sponsored By
WORKSRIGHT SOFTWARE

Do you need area code information?
Do you need ZIP Code information?
Do you need ZIP+4 information?
Do you need city name information?
Do you need county information?
Do you need a nearest dealer locator system?

We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

Just call us and we'll arrange for 30 days FREE use of either
ZIP/CITY or PER/ZIP4.

WorksRight Software, Inc.
Phone: 601-856-8337
Fax: 601-856-9432
E-mail: software@worksright.com
Web site: www.worksright.com


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

Sirius Computer Solutions:  A comprehensive, cost-effective cloud solution for IBM i users
BCD:  FREE Webinar: Making the Business Case for Web Enabling Your Green Screens. Nov 1
ITJ Bookstore:  Bookstore BLOWOUT!! Up to 50% off all titles! Everything must go! Shop NOW


 

IT Jungle Store Top Book Picks

Bookstore Blowout! Up to 50% off all titles!

The iSeries Express Web Implementer's Guide: Save 50%, Sale Price $29.50
The iSeries Pocket Database Guide: Save 50%, Sale Price $29.50
Easy Steps to Internet Programming for the System i: Save 50%, Sale Price $24.97
The iSeries Pocket WebFacing Primer: Save 50%, Sale Price $19.50
Migrating to WebSphere Express for iSeries: Save 50%, Sale Price $24.50
Getting Started with WebSphere Express for iSeries: Save 50%, Sale Price $24.50
The All-Everything Operating System: Save 50%, Sale Price $17.50
The Best Joomla! Tutorial Ever!: Save 50%, Sale Price $9.98


 
The Four Hundred
Thanks For The (Higher Priced) Memories?

Knowledge Is Power When Assessing Your IBM i Legacy

Server Sales Hiccup Stalls Avnet In September Quarter, December Sobering Up

As I See It: Born Again Computers

Gartner Says Big Data Getting Bigger, Skills Lag

Four Hundred Stuff
Raz-Lee Tracks IBM i PTFs, Ships Password Reset Product

Single Sign-On Service Cuts Costs, Complexity

Lavastorm Adopts R for Better Big Data Understanding

QlikTech Adapts In-Memory Analytics for External Big Data

SAP Sends HANA to the Cloud

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

System i PTF Guide
October 27, 2012: Volume 14, Number 43

October 20, 2012: Volume 14, Number 42

October 13, 2012: Volume 14, Number 41

October 6, 2012: Volume 14, Number 40

September 29, 2012: Volume 14, Number 39

September 22, 2012: Volume 14, Number 38

September 15, 2012: Volume 14, Number 37

TPM at The Register
Oracle rolls up and rolls out Solaris 11.1 update

VMware helps Hadoop roam the Serengeti a little easier

Dell lends Apache ARM software efforts a hand

Super Micro bends metal for Super Hadooper data munchers

Unisys tastes red ink in mouth after pension chop-slap

Cloudera's Project Impala rides herd with Hadoop elephant in real-time

VMware profits pinched in Q3, but not an pinchy as expected

Rackspace to ride Hortonworks elephant into the clouds

Cisco: Data centers are getting their cloudy acts together

Greenplum opens up Big Data control freak: Chorus for all of us

Riverbed Cascade appliances peek into VDI, SDN, CIFS

MapR simplifies and extends HBase for Hadoop

THIS ISSUE SPONSORED BY:

ProData Computer Services
WorksRight Software
Adsero Optima


Printer Friendly Version


TABLE OF CONTENTS
Running IBM i Access 7.1 and Windows 8

Data Structures Make Good Status Parameters

Changing Sub Tree Authorities In An IFS Folder

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