Previous Topic: Coding for Dataview ErrorsNext Topic: Handling Numeric Errors


Handling Errors in the FOR Construct

You can detect dataview errors and perform error processing in the FOR construct by coding a WHEN ERROR clause. Statements specified in the WHEN ERROR clause can access $ERROR functions and should resolve the error with a PROCESS NEXT or DO ERROR statement. If processing falls through to the ENDFOR, the $ERROR functions are no longer available.

In the following example, the WHEN ERROR statement evaluates the error condition when a dataview error occurs.

FOR FIRST CUSTOMER
  WHERE CUSTID = PNL-CUST
    DELETE CUSTOMER
WHEN NONE
  NOTIFY 'NO CUSTOMERS FOUND'
WHEN ERROR
  SELECT FIRST ACTION
    WHEN $ERROR-DVW-STATUS = 94 AND
         $ERROR-INTERNAL DVW-STATUS = 31
       LIST 'Constraint Error: ' $ERROR-CONSTRAINT-NAME
       NOTIFY 'Customer ' CUSTID 'has open orders and cannot be deleted'
    WHEN $ERROR-DVW-STATUS = 36
        NOTIFY 'Contact Database Administrator with error information'
    WHEN OTHER
        DO ERROR
  ENDSEL
ENDFOR

The values of the $ERROR functions contain different values, depending on the type of error and the type of dataview. For more information about $ERROR functions, see the Programming Reference Guide.