Please enable JavaScript to view this site.

R:BASE 11 Help

Navigation: Command Index > W

WHENEVER (Short Name: WHEN)

Scroll Prev Top Next More

Use the WHENEVER command in a program to check error conditions and run a set of commands designed to handle the error.

 

WHENEVER

 

Options

 

CONTINUE

Turns off error checking by the WHENEVER command.

 

GOTO lblname

Passes control to the command following the indicated LABEL command.

 

NOT FOUND

Indicates that no rows were found by the command (sqlcode equals 100).

 

SQLERROR

Indicates that a processing error of any type other than data-not-found was detected (sqlcode is less than zero).

 

About the WHENEVER Command

 

Use WHENEVER to trap errors when R:BASE Structured Query Language (SQL) commands are run. WHENEVER traps all SQL commands. For more information about structured query language, see Structured Query Language.

 

R:BASE places the error value of the specific error that occurs in the R:BASE system variable sqlcode. You can check the value of sqlcode to determine what action to take. The NOT FOUND errors always have the value 100; other errors are the negative of the R:BASE error code number.

 

Errors in R:BASE commands-not R:BASE SQL commands- do not affect the value of the sqlcode error variable. Use an R:BASE error variable to check for R:BASE command errors.

 

Using the Options

 

Enter a WHENEVER SQLERROR command at the beginning of a command file or command block to check for any SQL processing error other than data-not-found errors. WHENEVER applies only to that command or block. The system error variable sqlcode is set to the negative value of an error condition.

 

Enter a WHENEVER NOT FOUND command at the beginning of a command file or block to check for conditions such as No rows satisfy the WHERE clause or End-of-data encounteredthat occur within a program that is running.

 

The CONTINUE option turns off error checking and negates any previously entered WHENEVER command. That is, if you have entered a WHENEVER NOT FOUND with a GOTO, R:BASE runs the GOTO whenever data is not found. Then, if you enter a WHENEVER NOT FOUND command with a CONTINUE, data-not-found errors do not run the GOTO action. The GOTO action passes control to the specified label. You must have a matching LABEL command in the same command file or block within the procedure file running the WHENEVER command.

 

Example

 

In the following example, the DECLARE CURSOR and OPEN commands set a route to the transmaster table when the value of transid matches the value in the vtran variable. If the FETCH command does not find any rows, then R:BASE passes control to the commands that follow the LABEL command. The section after the LABEL command should contain commands to check the value of the sqlcode system variable and then perform some action according to the specific error condition that occurs.

 

WHENEVER NOT FOUND GOTO errors

.

.

.

DECLARE cur1 CURSOR FOR SELECT custid, netamount FROM +

  transmaster WHERE transid = .vtran

OPEN cur1

FETCH cur1 INTO vid, vamount

.

.

.

LABEL errors

*(error handling commands)