CALL Clause

Use the CALL clause to transfer program control to the specified UDR when the specified type of exception occurs. Do not include parentheses after the UDR name. The following WHENEVER statement causes the program to call the error_recovery() function if the program detects an error:
EXEC SQL WHENEVER SQLERROR CALL error_recovery;

When the UDR returns, execution resumes at the next statement after the line that is causing the error. If you want to halt execution when an error occurs, include statements that terminate the program as part of the specified UDR.

Observe the following restrictions on the specified routine:
  • The UDR cannot accept arguments nor can it return values. If it needs external information, use global variables or the WHENEVER ... GOTO option to transfer program control to a label that calls the UDR.
  • You cannot specify the name of an SPL routine in the CALL clause. To call an SPL routine, use the CALL clause to invoke a UDR that contains the EXECUTE FUNCTION (or EXECUTE PROCEDURE) statement.
  • Make sure that all functions within the scope of WHENEVER ... CALL statements can find a declaration of the specified function.

Related Statements

Related statements: EXECUTE FUNCTION statement, EXECUTE PROCEDURE statement, and FETCH statement

For discussions on exception handling and error checking, see the HCL OneDB™ ESQL/C Programmer's Manual.