Midrange News for the IBM i Community


Posted by: deepthi
error handling
has no ratings.
Published: 31 May 2012
Revised: 23 Jan 2013 - 1705 days ago
Last viewed on: 23 Sep 2017 (3477 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

error handling Published by: deepthi on 31 May 2012 view comments(5)

apart from indicators (Hi, Lo, Eq), built in function %error, monitor - on error block do we have any other ways in RPG to execute error handling at a program level - similar to program level MONMSG command in CLP.

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: Paulster
Premium member *
Sweden and The Netherlands
Comment on: error handling
Posted: 5 years 3 months 26 days 49 minutes ago

Hi D,

A number of RPG operation codes can be specified with (e), eg. write(e) and update(e). You can check the manual what operations make use of this feature After the operation with the (e) you can use %error() to establish if an error occurred or not.

For SQL you can check the variable sqlcode after execution of the SQL statement.

 

Good luck,

Paulster

Posted by: deepthi
Premium member *
Comment on: error handling
Posted: 5 years 3 months 25 days 23 hours 51 minutes ago
is there anything at program level, as i said similar to MONMSG specified immediately after declare statements in CLP - this will monitor all the errors in program.
Posted by: neilrh
Premium member *
Jackson, MI
Comment on: error handling
Posted: 5 years 3 months 25 days 19 hours 15 minutes ago
Edited: Thu, 31 May, 2012 at 08:30:02 (1942 days ago)

You mean something like: 

begsr *pssr;
  if not AlreadyError;
    AlreadyError = *on;
    dump(a);
  endif;
endsr '*cancl';

 Obviously it can be made more flashy, the above example produces a program dump spoolfile, and crashes out to the calling program with a generic "it's all gone really bad" message.

And the last time I wrote one of these was back in RPGIII, over 15 years ago, so some of the syntax might need some tidying up for RPGIV /free requirements.

Posted by: Ringer
Premium member *
Comment on: error handling
Posted: 5 years 3 months 25 days 19 hours 3 minutes ago

Yes, wrap a MONITOR/ON-ERROR/ENDMON around your entire mainline.

Monitor ;

   ... do EXSR, anything else,  etc.

On-Error ;

   ... had an error

EndMon ;

 

Chris R

Posted by: DaleB
Premium member *
Reading, PA
Comment on: error handling
Posted: 5 years 3 months 25 days 18 hours 20 minutes ago

I agree with Neil - *PSSR is the global exception routine for the main procedure and it's subroutines. If you're using traditional file I/O, you may also want an INFSR() on one or more files; note that a file's INFSR() could just point to *PSSR.

A subprocedure is a separate entry point, so each would have its own *PSSR. On the other hand, subprocedures generally are smaller chunks of code, so Ringer's wrap-around Monitor block could be practical.