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 section, 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 and an SQLDA can have any valid name.
Dynamic SQL is a 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 columns 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.
You can specify an INCLUDE SQLDA statement in an ILE RPG program; however, it is not allowed in free format. The format of the statement is:
C/EXEC SQL INCLUDE SQLDA C/END-EXEC
The INCLUDE SQLDA generates the following data structure.
D* SQL Descriptor area D SQLDA DS D SQLDAID 1 8A D SQLDABC 9 12B 0 D SQLN 13 14B 0 D SQLD 15 16B 0 D SQL_VAR 80A DIM(SQL_NUM) D 17 18B 0 D 19 20B 0 D 21 32A D 33 48* D 49 64* D 65 66B 0 D 67 96A D* D SQLVAR DS D SQLTYPE 1 2B 0 D SQLLEN 3 4B 0 D SQLRES 5 16A D SQLDATA 17 32* D SQLIND 33 48* D SQLNAMELEN 49 50B 0 D SQLNAME 51 80A D* End of SQLDA
The user is responsible for the definition of SQL_NUM. SQL_NUM must be defined as a numeric constant with the dimension required for SQL_VAR.
The INCLUDE SQLDA generates two data structures. The second data structure is used to setup and reference the part of the SQLDA that contains the field descriptions.
To set the field descriptions of the SQLDA the program sets up the field description in the subfields of SQLVAR and then assigns SQLVAR to SQL_VAR(n), where n is the number of the field in the SQLDA. This is repeated until all the field descriptions are set.
When the SQLDA field descriptions are to be referenced the user assigns SQLVAR(n) to SQL_VAR where n is the number of the field description to be processed.