RDB/VMS Relational Database Operator ON_ERROR — VMS RDB_4.1_M
Specifies the statement(s) the host language will perform if an error
occurs during the execution of the associated data manipulation
statement. The statements can be host language statements or Rdb/VMS
data manipulation statements.
NOTE
ON ERROR is supported only for the high-level
language preprocessors. ON ERROR is not supported
for RDO or Callable RDO.
Additional information available:
Format
ON ERROR ─┬─> statement ─┬─>
E
N
D
E
R
R
O
R └────────<─────┘ statement Any valid host language statement or Rdb/VMS data manipulation statement. Separate multiple statements with the appropriate delimiter or terminator according to the rules of the host language.
Example
This BASIC program uses LIB$MATCH_COND to handle errors that occur in
the MODIFY statement:
30
&RDB& START_TRANSACTION READ_WRITE
45 ! Input data
!
PRINT
INPUT "enter status code"; STATUS_CODE
PRINT
INPUT "enter status name"; STATUS_NAME
PRINT
INPUT "enter status type"; STATUS_TYPE
50 ! Modify the record
!
&RDB& FOR W IN WORK_STATUS
&RDB& MODIFY W USING
&RDB& ON ERROR
GOSUB 1000
&RDB& END_ERROR
&RDB& W.STATUS_CODE = STATUS_CODE;
&RDB& W.STATUS_NAME = STATUS_NAME;
&RDB& W.STATUS_TYPE = STATUS_TYPE
&RDB& END_MODIFY
PRINT
PRINT STATUS_CODE, STATUS_NAME, STATUS_TYPE
&RDB& END_FOR
GO TO 5000
1000 MATCH_COND = &
LIB$MATCH_COND(RDB$STATUS,RDB$_NOT_VALID)
SELECT MATCH_COND
CASE 1
PRINT "You have entered invalid data. Try again."
CALL SYS$PUTMSG(RDB$MESSAGE_VECTOR)
&RDB& ROLLBACK
GOTO 20
CASE 0
PRINT "Unknown error"
CALL SYS$PUTMSG(RDB$MESSAGE_VECTOR)
&RDB& ROLLBACK
GO TO 5000
END SELECT
RETURN
5000
&RDB& FINISH
END
This excerpt from a BASIC program performs the following actions:
o Prompts for input for the MODIFY statement.
o Starts a FOR loop.
o If an error occurs in the MODIFY statement, the program branches
to the call to LIB$MATCH_COND. This run-time library procedure
matches the condition value that Rdb/VMS returns to the program
(RDB$STATUS) with the condition code RDB$_NOT_VALID. If the
return status is RDB$_NOT_VALID, the program prints the
appropriate message and loops back to prompt again. If some
other error code is detected, "Unknown error" is displayed and
the program stops.
More
If you have invoked a database, you have the necessary privileges to use the ON_ERROR clause.