ERROR HANDLING TECHNIQUES - IBM Mainframe

As you plan and code, you naturally attempt to create a perfect program-one that will be bug-free and run without error. But it is unrealistic to believe that problems will never occur during your program's execution. Even if your own code is flawless, errors may occur in the system facilities that your program uses. Anticipate these possibilities by putting code into your program to handle them. Such code can be thought of as built-in distress flares or lifeboats. If such error-handling code is not present in your program, it could ruin your output data and files, and you might not even be aware of the problem.

The action taken by your error-handling code can vary from attempting to cope with the situation and continue, to issuing a message, to halting execution. In any event, coding a warning message is a good idea. You might be able to create your own error-detection routines for data-entry errors or for errors as your installation defines them. VS COBOL II contains special elements to help you anticipate and correct error conditions. These fall into four main areas:

  • User-initiated dumps
  • Arithmetic operations
  • STRING and UNSTRING operations
  • CALL statements

User-Initiated Dumps

You can cause a dump at any pre-specified point in your program by coding a call to the library routine ILBOABNO, for example:

User-Initiated Dumps

nnnn becomes the identifier in the nnnn user abend code produced with the resultant dump. Because of system limits, do not specify a value greater than 4095 for the user abend code. ILBOABNO is an RMODE(ANY) routine. It can be called statically or dynamically and can be passed a completion code variable from above the 16-megabyte line.

To force an abend at any point in your program, code: CALL 'ILBOABNO' USING data-name

This should not be used under CICS; instead, use the EXEC CICS ABEND command.

Arithmetic Operations

When your program performs arithmetic operations, the results may be larger than the fixed-point field that is to hold them, or you may have attempted a division by 0. In either case, the ON SIZE ERROR clause after the ADD, SUBTRACT, MULTIPLY, DIVIDE, or COMPUTE statement can handle the situation.

If you code the ON SIZE ERROR clause, the imperative statement of your clause will be executed and your result field will not be changed in the following five cases:

  • Fixed-point overflow
  • Division by 0
  • Zero raised to the zero power
  • Zero raised to a negative number
  • A negative number raised to a fractional power

You should be aware that floating-point exponent overflow, which occurs when the value of a floating-point arithmetic computation cannot be represented in the System-370 floating-point operand format, does not cause SIZE ERROR; an abend occurs instead.

STRING and UNSTRING Operations

When stringing or unstringing data, the pointer may fall beyond or short of the receiving field. In this case, a potential overflow condition exists. Although COBOL will not let the overflow actually occur, the STRING/UNSTRING operation will not be completed. If you do not have an ON OVERFLOW clause on the STRING or UNSTRING statement, control passes to the next sequential statement, and you are not notified of the incomplete operation.

CALL Statements

When dynamically calling a separately compiled program, the program that you call may be unavailable to the system. For example, the system may be out of storage or it may be unable to locate the load module. If you do not have an ON EXCEPTION or ON OVERFLOW clause on the CALL statement, your application may abnormally end (abend).

You can use the ON EXCEPTION clause to execute a series of statements and to perform your own error handling. So when you use an ON EXCEPTION statement and if the called program is unavailable, control will continue with the ON EXCEPTION clause.

The ON EXCEPTION clause applies only to the availability of the called program. If an error occurs while the called program is running, the ON EXCEPTION clause will not be executed


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

IBM Mainframe Topics