SQL Programming Manual for TAL

NonStop SQL Statements and Directives
HP NonStop SQL Programming Manual for TAL527887-001
3-7
CLOSE
A program or compilation unit can contain several Declare Sections; however, you
cannot nest Declare Sections (that is, put a Declare Section in another Declare
Section).
The TAL compiler does not recognize the SQL SOURCE directive. Use the TAL
SOURCE directive instead.
You can use TAL comment lines in a Declare Section.
The following declarations contain a Declare Section. You can use the variables
custnum and city as host variables in SQL statements; however, you cannot use the
variables SUPPLIER, ORDERS, ORDERNUM, DATE, or PARTCOST as host variables
because they are not declared in the Declare Section.
INT supplier;
STRUCT .orders;
BEGIN
INT ordernum;
STRING date[0:5];
END;
EXEC SQL BEGIN DECLARE SECTION;
INT custnum;
STRING city[0:14];
EXEC SQL END DECLARE SECTION;
INT partcost;
...
CLOSE
The CLOSE statement closes a cursor. After the CLOSE statement executes, the
result table established by the cursor no longer exists.
At run time, the OPEN statement for a cursor must execute before the CLOSE
statement (and all FETCH statements) for the cursor.
Determining the Scope of a Cursor for a CLOSE Statement
A static SQL cursor can only be used in the procedures in the compilation unit where
the cursor is declared. Thus, for static SQL operations, the DECLARE CURSOR,
OPEN, FETCH, DELETE, UPDATE, and CLOSE statements that refer to the cursor
must be in the same compilation unit.
If the program exits a procedure with an open cursor, procedures that execute later can
still refer to the cursor, provided the procedures are in the same compilation unit.
For a dynamic SQL cursor, all statements referring to the cursor must appear in the
procedure where the cursor is declared; however, if you open the cursor and use it in
one call to the procedure where it is declared, you can still use the cursor in
subsequent calls without opening the cursor again.