HP 3000 Manuals

Exception Handling [ HP ALLBASE/BRW Reference Manual ] MPE/iX 5.0 Documentation


HP ALLBASE/BRW Reference Manual

Exception Handling 

Exception values indicate whether the value of an item, function,
parameter or any expression is invalid.  HP ALLBASE/BRW distinguishes
between NO_VALUEs and ERROR_VALUEs:

   *   NO_VALUE signifies that an item or a result has no value.  Note
       that NO_VALUE means "no value." It does not, for example, mean
       that a numeric item has a value of 0.  NO_VALUEs can occur, for
       example, when you specify an open join on a source table.
       NO_VALUE is set for an SQL item having a NULL value.

       You can make a particular item value return NO_VALUE by using a
       calculated item with a formula liek:

            IF ANSWER = "NONE" THEN NO_VALUE ELSE ANSWER

   *   ERROR_VALUE is a name that includes the following:

------------------------------------------------------------------------------------------
|                                                                                        |
|               Value                                    Definition                      |
|                                                                                        |
------------------------------------------------------------------------------------------
|                                                                                        |
| OVERFLOW                           Numeric overflow occurred.                          |
|                                                                                        |
| DIVIDE_BY_ZERO                     Divide by zero occurred.                            |
|                                                                                        |
| INDEXVIOLATION                     Out of range index occurred.                        |
|                                                                                        |
| INVALID_VALUE                      For example, database contains letters in a display |
|                                    numeric field.                                      |
|                                                                                        |
------------------------------------------------------------------------------------------

You can use the BRWSETUP program to modify a BRWCONF file to print a
value when an exception condition occurs.  See Chapter 17  
"Configuration" for a description of the BRWSETUP program.  Note that
non-printable characters in strings do not cause an INVALID_VALUE.

Whenever a new exception value occurs, an execution warning message is
issued.  All execution warning messages are printed at the end of the
report.

This is an example of an exception report:
_________________________________________________________________
|                                                               |
|     The following exceptions occured in this report:          |
|                                                               |
|     Field  overflow occurred with item SALES-VALUE       (54*)|
|     Divide by zero occurred with item ORDER/STOCK-QTY    (12*)|
|                                                               |
_________________________________________________________________

            

The number to the right of the message indicates the number of times the
exception occurred in the report.

Automatic Exception Value Handling 

Automatic exception value handling means that a calculation produces an
exception value if one of the arguments has an exception value.  For
example, if one of the arguments in an addition has no value, the result
of the addition will also have no value.

HP ALLBASE/BRW uses an exception algorithm for calculations.  If one of
the arguments has an exception value, then an exception value results.
Note that this does not apply to operators =, <>, AND, OR. The table
below shows how the system handles arguments with exception values:

-----------------------------------------------------------------------------------------------
|                              |                              |                               |
|          Argument 1          |          Argument 2          |            Result             |
|                              |                              |                               |
-----------------------------------------------------------------------------------------------
|                              |                              |                               |
|              ok              |              ok              |              ok               |
|                              |                              |                               |
-----------------------------------------------------------------------------------------------
|                              |                              |                               |
|              ok              |           no value           |           no value            |
|                              |                              |                               |
-----------------------------------------------------------------------------------------------
|                              |                              |                               |
|              ok              |            error             |             error             |
|                              |                              |                               |
-----------------------------------------------------------------------------------------------
|                              |                              |                               |
|           no value           |            error             |             error             |
|                              |                              |                               |
-----------------------------------------------------------------------------------------------

Comparisons for equal or not equal are always true or false.  Same
exception values will be treated as equal.  Comparisons for less or
greater cannot be true or false if one argument has an exception value,
so the comparison result will be an exception value (which is interpreted
as false if it is used for a selection).

Boolean operators AND and OR use the following logic:

-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
|      Argument 1       |      Argument 2       |          AND          |          OR           |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
|         false         |         false         |         false         |         false         |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
|         true          |         false         |         false         |         true          |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
|         true          |         true          |         true          |         true          |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
|         false         |       no value        |         false         |       no value        |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
|         true          |       no value        |       no value        |         true          |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
|         false         |         error         |         false         |         error         |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------
|                       |                       |                       |                       |
|         true          |         error         |         error         |         true          |
|                       |                       |                       |                       |
-------------------------------------------------------------------------------------------------

Note that indexes or conditions which have exception values produce
exception values as calculation results.

Testing For and Assigning Exception Values 

You can test for exception values or assign the result of a calculation
to an exception value.

Example 

Suppose you might want to have the report automatically insert the
current month as the value for the parameter ?MONTH if the parameter has
no value.  You could use a condition such as the following:

     IF ?month = NO_VALUE
     THEN
        month_of (date)         <<current month>>
     ELSE
        ?month

Suppose you have a report where the calculated item BUDGET selects the
current year, previous year or next year budget depending on the
parameter ?YEAR. If ?YEAR has any other value, the budget value produces
an error.

     IF ?year = "CURRENT" THEN cy-budget
     ELSE IF ?year = "PREVIOUS" THEN py-budget
       ELSE IF ?year = "NEXT" THEN ny-budget
         ELSE ERROR_VALUE

Avoiding Exceptions 

In some cases, you want to avoid exceptions in your report.

Example 

If the divisor operand in a division is potentially zero and you do not 
want an exception value as the division result, use the following
condition:

     IF b <> 0 THEN a / b ELSE 0

Related Sections 

   *   Arguments

   *   Conditions/Boolean Operators

   *   Column Calculation Results



MPE/iX 5.0 Documentation