HPlogo ALLBASE/SQL COBOL Application Programming Guide: HP 9000 Computer Systems > Chapter 3 Embedding SQL Commands

Implicit Status Checking

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

In the PROCEDURE DIVISION, you can use the WHENEVER command, as at 7 in Figure 3-1 “Sample Program COBEX2 ”, to have ALLBASE/SQL examine SQLCA values and cause a specific action to be taken. The WHENEVER command is a preprocessor directive that specifies the action to be taken if an error or warning condition occurs when each subsequent SQL command is executed:



        EXEC SQL WHENEVER SQLERROR GO TO S400-SQL-ERROR END-EXEC.

                          |        |

                          |        |

                          |        |

                          |        the action

                          |

                          the condition

Each WHENEVER command affects all ALLBASE/SQL commands that follow it in the source listing until another WHENEVER command is encountered.

If execution of the SELECT command at 8 causes an error condition, control passes to paragraph S400-SQL-ERROR because the WHENEVER command shown above precedes the COMMIT WORK RELEASE and SELECT commands in the source listing.

The WHENEVER SQLWARNING and WHENEVER NOT FOUND commands at 7 specify where to pass control when a warning condition occurs or when no row satisfies the WHERE clause in the SELECT command.

Although you can use a WHENEVER command to have ALLBASE/SQL examine the values in certain fields of the SQLCA, you can also examine the values yourself, as discussed under "Explicit Status Checking" later in this chapter.

Feedback to webmaster