[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
HP COBOL
|
Previous | Contents | Index |
Your program must contain logic to accommodate exceptions and errors.
The items of syntax in HP COBOL that are used for this purpose are
ON ERROR, AT END, and USE.
4.8.1 Database On Error Condition
The database on error exception condition occurs when the DBCS encounters a database exception condition for any data manipulation language (DML) statement.
The ON ERROR phrase in a DML statement allows the selection of an imperative statement sequence when any database exception condition occurs.
The NOT ON ERROR phrase allows execution of an imperative statement when a database exception condition does not occur.
Stment is an imperative statement.
When a database exception condition occurs and the statement contains an ON ERROR phrase:
When a database exception condition occurs and the statement does not contain an ON ERROR phrase:
When a database exception condition does not occur:
Use the ON ERROR phrase to transfer execution control to the associated statements' error handling routine, where your program can supply useful and effective debugging information. (See Section 4.8.3 for examples and Glossary of Oracle DBMS-Related Terms for more information on Oracle CODASYL DBMS Database Special Registers.) The ON ERROR phrase can be part of every DML statement. It allows you to plan the graceful termination of a program that would otherwise terminate abnormally. (In a FETCH or FIND statement, you cannot specify both the ON ERROR and AT END phrases in the same statement.) For example:
PROCEDURE DIVISION. . . . RECONNECT PARTS_RECORD WITHIN ALL ON ERROR DISPLAY "Exception on RECONNECT" PERFORM PROCESS-EXCEPTION. . . . PROCESS-EXCEPTION. DISPLAY "Database Exception Condition Report". DISPLAY " ". DISPLAY "DB-CONDITION = ", DB-CONDITION WITH CONVERSION. DISPLAY "DB-CURRENT-RECORD-NAME = ", DB-CURRENT-RECORD-NAME. DISPLAY "DB-CURRENT-RECORD-ID = ", DB-CURRENT-RECORD-ID WITH CONVERSION. DISPLAY " ". CALL "DBM$SIGNAL". STOP RUN. |
An at end condition occurs when a program detects the end of a file. The at end condition may occur as a result of a FETCH or FIND statement execution in your database program. You use the AT END phrase to specify the action your program is to take when an at end condition occurs.
The NOT AT END phrase specifes the action your program takes if an AT END does not occur.
Use the AT END phrase of the FETCH and FIND statements to handle the end of a collection of records condition. Your program will terminate if: (1) an at end condition occurs, (2) the program does not include the AT END phrase, and (3) there is no applicable USE statement.
When an at end condition occurs and the statement contains an AT END phrase:
When an at end condition occurs and the statement does not contain an AT END phrase:
When an at end condition (or any other error condition) does not occur:
Planning for exception conditions is an effective way to increase program and programmer productivity. A program with USE statements is more flexible than a program without them. They minimize operator intervention and often reduce or eliminate the time you need to debug and rerun the program.
The USE statement traps unsuccessful run-time Oracle CODASYL DBMS exception conditions that cause the execution of a Declaratives procedure. A Declaratives procedure can:
Two sets of USE statements follow:
USE [ GLOBAL ] FOR DB-EXCEPTION. |
Example 4-1 A Single USE Statement |
---|
PROCEDURE DIVISION. DECLARATIVES. 200-DATABASE-EXCEPTIONS SECTION. USE FOR DB-EXCEPTION. DB-ERROR-ROUTINE. DISPLAY "Database Exception Condition Report". DISPLAY "-------------------------------------------". DISPLAY "DB-CONDITION = ", DB-CONDITION WITH CONVERSION. DISPLAY "DB-CUR-REC-NAME = ", DB-CURRENT-RECORD-NAME. DISPLAY "DB-CURRENT-RECORD-ID = ", DB-CURRENT-RECORD-ID WITH CONVERSION. DISPLAY "DB-CUR-REC-ID = ", DB-CRID. DISPLAY " ". CALL "DBM$SIGNAL". END DECLARATIVES. |
maximum
USE [GLOBAL] FOR DB-EXCEPTION ON DBM$_exception-condition [, DBM$_exception-condition]... |
A Format 1 database declarative executes whenever a database
exception condition occurs and the corresponding
DBM$_exception-condition is explicitly stated in the USE statement.
USE [ GLOBAL ] FOR DB-EXCEPTION ON OTHER. |
A Format 2 declarative executes whenever a database exception
condition occurs and the corresponding DBM$_exception-condition is not
explicitly stated in any Format 1 USE statement.
Example 4-2 Multiple USE Statements |
---|
PROCEDURE DIVISION. DECLARATIVES. 200-DATABASE-EXCEPTIONS SECTION. USE FOR DB-EXCEPTION ON DBM$_CRELM_NULL, DBM$_CRTYPE_NULL. 200-DATABASE. PERFORM 300-REPORT-DATABASE-EXCEPTIONS. IF DB-CONDITION = ..... GO TO ... IF DB-CONDITION = ..... GO TO ... STOP RUN. 225-DATABASE-EXCEPTIONS SECTION. USE FOR DB-EXCEPTION ON DBM$_DUPNOTALL. 225-DATABASE. PERFORM 300-REPORT-DATABASE-EXCEPTIONS. GO TO ... 250-DATABASE-EXCEPTIONS SECTION. USE FOR DB-EXCEPTION ON OTHER. 250-DATABASE. PERFORM 300-REPORT-DATABASE-EXCEPTIONS. EVALUATE DB-CONDITION WHEN ..... GO TO ... WHEN ..... GO TO ... WHEN ..... GO TO ... WHEN ..... GO TO ... WHEN ..... GO TO ... WHEN ..... GO TO ... WHEN ..... GO TO ... WHEN ..... GO TO ... WHEN ..... GO TO ... WHEN OTHER PERFORM... . STOP RUN. 300-REPORT-DATABASE-EXCEPTIONS. DISPLAY "Database Exception Condition Report". DISPLAY " ". DISPLAY "DB-CONDITION = ", DB-CONDITION WITH CONVERSION. DISPLAY "DB-CUR-REC-NAME = ", DB-CURRENT-RECORD-NAME. DISPLAY "DB-CURRENT-RECORD-ID = ", DB-CURRENT-RECORD-ID DISPLAY " ". CALL "DBM$SIGNAL". |
Previous | Next | Contents | Index |