SQL$HELP_OLD72.HLB  —  DECLARE  STATEMENT  Example
    Example 1: Declaring a statement name in a PL/I program

    This example shows a program line that declares a statement name
    DYNAMIC_STATEMENT. Later lines in the example show how DECLARE
    CURSOR, PREPARE, and DESCRIBE statements refer to it. Because
    you do not have to declare a statement explicitly, the DECLARE
    STATEMENT statement is always optional.

    EXEC SQL DECLARE DYNAMIC_STATEMENT STATEMENT;
    /* Declare the SQL Communications Area. */
    EXEC SQL INCLUDE SQLCA;
    /* Declare the SQL Descriptor Area. */
    EXEC SQL INCLUDE SQLDA;

    /* The program declares the host language variable
       STATEMENT_STRING and stores in it the
       character string containing a SELECT
       statement to be executed dynamically. */
                    .
                    .
                    .
    EXEC SQL DECLARE CURSOR1 CURSOR FOR DYNAMIC_STATEMENT;
    EXEC SQL PREPARE OBJECT_STATEMENT FROM STATEMENT_STRING;
    EXEC SQL DESCRIBE OBJECT_STATEMENT INTO SQLDA;

    /* The program sets up pointers in the
       SQLDATA field of the SQLDA to the data
       area (host language variables or dynamic
       memory, for example) to receive the data
       from the cursor. */
                    .
                    .
                    .
    EXEC SQL OPEN CURSOR1;

    DO WHILE (SQLCODE = 0);
            EXEC SQL FETCH CURSOR1 USING DESCRIPTOR SQLDA;

    /* The program prints or otherwise
    processes rows of the result tables. */
                    .
                    .
                    .

    END;

    EXEC SQL CLOSE CURSOR1;
Close Help