AS/400: How to handle errors in RPG or RPGLE

450 pts.
Tags:
AS 400
RPG
RPGLE
How to handle errors in RPG/RPGLE? How to handle calculation errors example array bound errors or division or hexadecimal errors?
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

The easiest way to avoid these is to test the data before the calculation is performed. Better yet is make sure you cannot have bad data in the database at all. It should be verified before it is written to your production data to prevent job halts during processing. How to handle these in RPG is tougher than a CL where MONMSG can be used. If you need more specifics we need more details and an example. 

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • TheRealRaven
    The question needs examples of code that demonstrate errors. There is no good way to answer without seeing an error in code that needs handling. Different versions of RPG and different styles of coding will call for different handling. There is no useful answer otherwise. Code that uses (E) extenders for example won't benefit much from MONITOR blocks.
    34,990 pointsBadges:
    report
  • vivekntt21
    Suppose we are dividing a number by zero will result in infinity. So how to handle such types of errors in RPG or RPGLE?
    450 pointsBadges:
    report
  • azohawk

    example  c = a/b;

    if b <> *zero;

    c = a / b;

    else;

    c = *zero;

    endif;

    4,055 pointsBadges:
    report
  • ToddN2000
    Like Azohawk shows in his example test the value before the calculation is performed. For other possible issues where something may fail I have learned to check the data before it's written to the database. This eliminates practically all errors. All but those that may have changed the data via an SQL command, After 30+ years of coding you really need to make your code fool proof.
    132,520 pointsBadges:
    report
  • ToddN2000
    For other ways to validate and correct data issue on entry use the CHECK() function in the DDS.
    things like 
    CHECK(ME) for mandatory entry
    CHECK(RZ) right adjust zero fill 

    For full info check out DDS CHECK()
    132,520 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: