3. Embedded SQL for COBOL : The SQL Communications Area : Error Handling Using the SQLCA : Whenever Goto Action in Embedded SQL Blocks
 
Share this page                  
Whenever Goto Action in Embedded SQL Blocks
The words begin and end delimit an embedded SQL block‑structured statement is a statement. For example, the select loop and the unloadtable loops are both block‑structured statements. You can only terminate these statements using the methods specified for the particular statement in the SQL Reference Guide. For example, the select loop is terminated either when all the rows in the database result table have been processed or by an endselect statement. The unloadtable loop is terminated either when all the rows in the forms table field have been processed or by an endloop statement.
Therefore, if you use a whenever statement with the goto action in an SQL block, you must avoid going to a paragraph outside the block. Such a goto causes the block to be terminated without issuing the runtime calls necessary to clean up the information that controls the loop. (For the same reason, you must not issue a COBOL GO TO statement that causes control to leave or enter the middle of an SQL block.) The target of the whenever goto statement must be a paragraph in the block. If, however, it is a paragraph containing a block of code that cleanly exits the program, you do not need to take the above precaution.
The above information does not apply to error handling for database statements issued outside an SQL block, or to explicit hard‑coded error handling. For an example of hard‑coded error handling, see The Table Editor Table Field Application (see page The Table Editor Table Field Application) in this chapter.