There are two types of SQL descriptor areas. One is defined with the ALLOCATE DESCRIPTOR statement. The other is defined using the SQLDA structure. In this topic, only the SQLDA form is discussed.
The following statements can use an SQLDA:
Unlike the SQLCA, there can be more than one SQLDA in a program. The SQLDA can have any valid name. An SQLDA can be coded in a COBOL program directly or added with the INCLUDE statement. Using the SQL INCLUDE statement requests the inclusion of a standard SQLDA declaration:
EXEC SQL INCLUDE SQLDA END-EXEC.
The COBOL declarations included for the SQLDA are:
1 SQLDA. 05 SQLDAID PIC X(8). 05 SQLDABC PIC S9(9) BINARY. 05 SQLN PIC S9(4) BINARY. 05 SQLD PIC S9(4) BINARY. 05 SQLVAR OCCURS 0 TO 409 TIMES DEPENDING ON SQLD. 10 SQLTYPE PIC S9(4) BINARY. 10 SQLLEN PIC S9(4) BINARY. 10 FILLER REDEFINES SQLLEN. 15 SQLPRECISION PIC X. 15 SQLSCALE PIC X. 10 SQLRES PIC X(12). 10 SQLDATA POINTER. 10 SQLIND POINTER. 10 SQLNAME. 49 SQLNAMEL PIC S9(4) BINARY. 49 SQLNAMEC PIC X(30).
SQLDA declarations must appear in the WORKING-STORAGE SECTION or LINKAGE SECTION of your program and can be placed wherever a record description entry can be specified in those sections. For ILE COBOL for iSeries™, the SQLDA is declared using the GLOBAL clause.
Dynamic SQL is an advanced programming technique. With dynamic SQL, your program can develop and then run SQL statements while the program is running. A SELECT statement with a variable SELECT list (that is, a list of the data to be returned as part of the query) that runs dynamically requires an SQL descriptor area (SQLDA). This is because you cannot know in advance how many or what type of variables to allocate in order to receive the results of the SELECT.