Show TOC

WHENEVER Statement [ESQL]Locate this document in the navigation structure

Specifies error handling in an Embedded SQL program.

Syntax
WHENEVERSQLERROR | SQLWARNING | NOTFOUND }
   … { GOTO <label> | STOP | CONTINUE | <C code;> }
Examples

(back to top)

  • Example 1 This example executes done when the NOTFOUND clause is met:
    EXEC SQL WHENEVER NOTFOUND GOTO done;
  • Example 2 this example uses the SQLERROR clause:
    EXEC SQL WHENEVER SQLERROR
    	{ 
    		PrintError( &sqlca ); 
    		return( FALSE ); 
    	};
Usage

(back to top)

WHENEVER can be put anywhere in an Embedded SQL C program, and does not generate any code. The preprocessor generates code following each successive SQL statement. The error action remains in effect for all Embedded SQL statements from the source line of the WHENEVER statement until the next WHENEVER statement with the same error condition, or the end of the source file.

The default action is CONTINUE.

WHENEVER is provided for convenience in simple programs. Most of the time, checking the sqlcode field of the SQLCA (SQLCODE) directly is the easiest way to check error conditions. In this case, WHENEVER is not used. The WHENEVER statement causes the preprocessor to generate an <if ( SQLCODE )> test after each statement.

Note

The error conditions are in effect based on positioning in the C language source file and not on when the statements are executed.

Standards

(back to top)

  • SQL—Vendor extension to ISO/ANSI SQL grammar.
  • SAP Database products—Supported by Open Client/Open Server.
Permissions