Rational Developer for System z
COBOL for Windows, Version 7.5, Programming Guide


Example: checking for division by zero

The following example shows how you can code an ON SIZE ERROR imperative statement so that the program issues an informative message if division by zero occurs.

DIVIDE-TOTAL-COST.
    DIVIDE TOTAL-COST BY NUMBER-PURCHASED
        GIVING ANSWER
        ON SIZE ERROR
          DISPLAY “ERROR IN DIVIDE-TOTAL-COST PARAGRAPH”
          DISPLAY “SPENT ” TOTAL-COST, “ FOR ” NUMBER-PURCHASED
          PERFORM FINISH
    END-DIVIDE
    . . .
    FINISH.
    STOP RUN.

If division by zero occurs, the program writes a message and halts program execution.


Terms of use | Feedback

Copyright IBM Corporation 1996, 2008.
This information center is powered by Eclipse technology. (http://www.eclipse.org)