Using an SQL statement in an application program

You can include SQL statements in a source program that will be submitted to the IMS coprocessor. An SQL statement can be placed anywhere in the application program where a host language statement is allowed. Each statement must be preceded by a keyword (or keywords) to indicate that the statement is an SQL statement.

Executable statements: An executable SQL statement in an application program is executed every time a statement of the host language would be executed if specified in the same place. (Thus, for example, a statement within a loop is executed every time the loop is executed, and a statement within a conditional construct is executed only when the condition is satisfied.)

An SQL statement can contain references to host variables. A host variable referred to in this way can be used in one of two ways:

As input
The current value of the host variable is used in the execution of the statement.
As output
The variable is assigned a new value as a result of executing the statement.

In particular, all references to host variables in predicates are effectively replaced by current values of the variables; that is, the variables are used as input. The treatment of other references is described individually for each statement.

The successful or unsuccessful execution of the statement is indicated by setting the SQLIMSCODE and SQLIMSSTATE fields in the included SQLIMSCA. You must therefore follow all executable statements by a test of SQLIMSCODE or SQLIMSSTATE. Alternatively, you can use the WHENEVER statement (which is itself nonexecutable) to change the flow of control immediately after the execution of an SQL statement.

Nonexecutable statements: An nonexecutable statement is processed only by the coprocessor. The coprocessor reports any errors encountered in the statement. The statement is never executed, and acts as a no-operation if placed among executable statements of the application program. Therefore, do not follow such statements with a test of an SQL return code.