Defining SQL descriptor areas in COBOL applications that use SQL
There are two types of SQL descriptor areas (SQLDAs). 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:
- EXECUTE…USING DESCRIPTOR descriptor-name
- FETCH…USING DESCRIPTOR descriptor-name
- OPEN…USING DESCRIPTOR descriptor-name
- CALL…USING DESCRIPTOR descriptor-name
- DESCRIBE statement-name INTO descriptor-name
- DESCRIBE CURSOR cursor-name INTO descriptor-name
- DESCRIBE INPUT statement-name INTO descriptor-name
- DESCRIBE PROCEDURE procedure-name INTO descriptor-name
- DESCRIBE TABLE host-variable INTO descriptor-name
- PREPARE statement-name INTO descriptor-name
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:
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, 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.