Skip to content

Overflow Clause

The OVERFLOW clause tells report writer how to protect your program from arithmetic errors, such as zero divide, that would cause an elementary COBOL program to fail. The SUM OVERFLOW clause tells report writer what action to take if a total field overflows - an event which is more likely to happen than with other report fields. It may be difficult to estimate the number of digits needed for totals, since this will depend on the number and content of items to be accumulated into the totals. Use these clauses if you need to change the standard action.

overflow clause

Overflow Clause: Coding Rules

  • The OVERFLOW (format a) and SUM OVERFLOW clauses (format b) are distinct clauses and you may choose a different option for each.

  • If your program contains no SUM clauses, the SUM OVERFLOW clause is not required. Similarly, if your program has no clauses of the form SOURCE arithmeticexpression , the OVERFLOW clause is not required. In either case, the clause may nevertheless be coded and it then has no effect.

  • Use the OMITTED option if your report uses arithmetic expressions or has a SUM clause respectively but there is no likelihood of a size error.

  • Use the REPLACE BY option if your report may be sensitive to improbable values in the user's data and you would like to show on the report exactly where errors have occurred. REPLACE BY can be followed by either a numeric or a non-numeric literal-1, whatever the PICTURE of your report field.

  • Use the STOP option only if SUM or arithmetic overflow is extremely unlikely but potentially damaging and you are content for your program to execute an "emergency" COBOL STOP in such a case.

Overflow Clause: Operation

  • The OVERFLOW clause takes effect if your program contains clauses of the form SOURCE arithmetic-expression. On each occasion that the expression is evaluated a check may be made in case the result is too large for the report field. Also, if any expression involves a division step there could be a zero divide error, such as FIELD-A / FIELD-B when FIELD-B contains zero.

  • The SUM OVERFLOW clause takes effect if your program contains a SUM clause. On each addition, a check may be performed for size error. This clause does not affect any of the other functions of the SUM clause, such as the resetting (zeroing) of the totals. The default in each case is STANDARD (see below).

  • If you choose the OMITTED option the effect is as follows:

    • OVERFLOW: Report writer will not perform any checks for arithmetic overflow. This will save a small overhead on the evaluation of expressions. If a size error occurs, then at best our report field will have some high-order digits truncated. If a zero divide error occurs, your program will fail at run time.

    • SUM OVERFLOW: Report writer will not perform any checks for SUM overflow. This will save a small overhead on totalling. If a size error occurs, at least one top digit will be truncated and lost from the total field.

  • If you choose the STANDARD option, the effect is as follows:

    • OVERFLOW: Report writer will always check for size error, or zero divide, when it evaluates each SOURCE expression. If this happens, your report field will be blank and a run time error 10 will be indicated.

    • SUM OVERFLOW: Report writer will check for size error on each addition into a total field. If this happens, a run time error 11 will be indicated. No adding will take place into your total field and you will obtain the total up to the point just after the last valid addition.

  • If you code the REPLACE BY option, the effect is as follows:

    • OVERFLOW: Report writer will check for a size error or zero divide and, if this occurs, it will place your specified literal-1 in the SOURCE report field instead of the erroneous value.

    • SUM OVERFLOW: Report writer will check for a size error and, if this occurs, it will place your specified literal-1 in the SUM report field instead of the erroneous value.

    In either case, if you choose a numeric literal-1, this value will be stored according to the rules of the MOVE statement. If you choose a non-numeric literal-1, the literal will be stored, as for a MOVE, in your report field, treated as though it were redefined as an unedited alphanumeric field (PIC X...). For example, if overflow occurs and your report field is defined as: 05 COL 20 PIC ZZZ9.99 SOURCE NUM-ORDERED * UNIT-PRICE. and your RD contains the clause: OVERFLOW PROCEDURE IS REPLACE BY ZERO, the following will appear:

    replace by zero

    and if your RD contains the clause: OVERFLOW PROCEDURE IS REPLACE BY ALL "?", the following will appear:

    replace by all

  • If you code the STOP option, report writer will execute a COBOL STOP literal-2 as soon as an error is detected.

Compatibility

The OVERFLOW and SUM OVERFLOW clauses are unique to new Report Writer. The SUM OVERFLOW IS OMITTED option emulates the effect of OS/VS and DOS/VS COBOL's builtin Report Writer.

Back to top