The COMPOUND statement is one of the control statements in routines. It executes further SQL statements in a common context. Common local data, common local cursors, and common exception routines apply for these SQL statements.
A detailed description of the COMPOUND statement is provided on "COMPOUND - Execute SQL statements in a common context".
Local data
Local data comprises variables or exception names which can only be addressed in the COMPOUND statement.
The names of the local data must differ from each other.
A data type and, if required, a default value is defined for variables. They have no indicator variable. They can be used in local cursor definitions, local exception routines, and the SQL statements of the COMPOUND statement.
To facilitate understanding, exception names define a name for an exception (without specifying an associated SQLSTATE) or a name for an SQLSTATE. They can be used in local exception routines, see "COMPOUND - Execute SQL statements in a common context".
Local cursors
With the definition of local cursors, cursors are defined which can only be addressed in the COMPOUND statement.
The names of the local cursors must differ from each other.
Local cursors can be used in local exception routines and the SQL statements of the COMPOUND statement.
Local cursors are defined without the WITH HOLD clause. The SQL statements STORE and RESTORE may not be applied to local cursors.
Common exception routines
The definition of exception routines determines what response is made when, during processing of an SQL statement in the context of the COMPOUND statement, an SQLSTATE ≠ '00000' is reported.
When an SQLSTATE occurs which was specified in an exception routine, the exception routine for the SQLSTATE is executed. For other SQLSTATEs, SESAM/SQL automatically performs exception handling.
The type of exception handling is defined in the exception routines in accordance with the SQLSTATE. When an exception occurs, further SQL statements there decide whether the routine should be continued or terminated. Changes which were made in the context of the COMPOUND statement can be undone.