SQL Programming Manual for Pascal

NonStop SQL Statements and Directives
HP NonStop SQL Programming Manual for Pascal528614-001
3-7
INVOKE and SOURCE in the Declare Section
ORDERS, ORDERNUM, DATE, or PARTCOST cannot be used as host variables
because they are not declared within the Declare Section.
{ Variable declarations: }
VAR SUPPLIER : INT16;
TYPE
ORDTYPE = RECORD
ORDERNUM : INT16;
DATE : FSTRING (6);
END;
ORD = ARRAY [ 1..10] OF ORDTYPE;
VAR ORDERS : ORD;
EXEC SQL BEGIN DECLARE SECTION;
VAR CUSTNUM : INT16;
CITY : FSTRING (14);
EXEC SQL END DECLARE SECTION;
VAR PARTCOST : INT16;
INVOKE and SOURCE in the Declare Section
You can use two host language directives in a Declare Section: SQL INVOKE and
Pascal SOURCE. The INVOKE statement causes the compiler to generate a specified
table or view description. The SOURCE directive causes the compiler to copy text from
a source file. For example:
{ Declare columns in the PARTS table as host variables: }
EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL INVOKE SALES.PARTS;
EXEC SQL END DECLARE SECTION;
{ Declarations from Pascal source file INVARS: }
EXEC SQL BEGIN DECLARE SECTION;
?SOURCE $disk3.decs.invars;
EXEC SQL END DECLARE SECTION;
CLOSE
The CLOSE statement closes a cursor. After the CLOSE statement executes, the
virtual table established by the cursor no longer exists.
A static SQL cursor can be referred to only by the procedures in the same compilation
unit in which the cursor was declared. This means that for static SQL programs, the
DECLARE CURSOR, OPEN, FETCH, DELETE WHERE CURRENT, UPDATE
WHERE CURRENT, and CLOSE statements must be in the same compilation unit.
For dynamic SQL cursors, all statements referencing the cursor must be in the same
procedure where the cursor was declared.