Was this helpful?
How to Declare an SQLDA Variable
Once the SQLDA record definition has been included (or hard coded) the program can declare an SQLDA variable. This record variable must be declared outside of an Embedded SQL declare section, as the preprocessor does not understand the special meaning of the SQLDA record or the IISQLDA record type. When you use the variable in the context of a Dynamic SQL or Dynamic FRS statement, the preprocessor accepts any object name, and assumes that the variable refers to a legally declared SQLDA record variable. If a program requires an SQLDA record variable with the same number of sqlvar variables as in the IISQLDA record type, then it can accomplish this as in:
exec sql include sqlda ! Defines record type
    declare iisqlda sqlda ! Declares sqlda record variable
    sqlda::sqln = iisq_max_cols ! set the size

    exec sql describe s1 into :sqlda
Normally the same SQLDA can be used across various BASIC subroutines and external procedures. In these cases you can declare the SQLDA using any one of the BASIC storage classes, such as common or external. For example the above declaration could also have been:
exec sql include sqlda
 common (sqlda_area) iisqlda sqlda
    ! declares global sqlda
At other times you may want to dynamically allocate your SQLDA record variable out of another storage area. In that case you can use various BASIC map statements to define the position of the SQLDA in the storage area. However, you must confirm that the SQLDA record variable being used is a valid SQLDA, with storage allocated to it.
If a program requires an SQLDA variable with a different number of sqlvar variables (not IISQ_MAX_COLS), the program can then define its own record type and declare its own variable. For example:
record MY_SQLDA ! Record type with 50 elements
        string     myid = 8
        long     mybc
        word        myvars
        word        mycols
        group    vararray(50)
            word     vartype
            word varlen
            long vardata
            long varind
            group varname
                word varnamel
                string varnamec = 34
            end group varname
        end group vararray
end record MY_SQLDA

declare MY_SQLDA myda        ! SQLDA variable

myda::myvars = 50         ! Set the size

exec sql describe s1 into :myda
In the above record type definition, the names of the record members are not the same as those of the IISQLDA record, but their layout is identical.
Last modified date: 06/10/2024