Previous Topic: DescriptionNext Topic: DROP


Example

In the following COBOL example of an SQLDA, a table or view with up to 100 columns is described. (For more information on SQLDAs used in DESCRIBE statements, see SQLDA (DESCRIBE or PREPARE INTO Statements).)

          01  SQLDA
              05  SQLAID                PIC X(8)  VALUE 'SQLDA   '.
              05  SQLABC                PIC S9(9) COMP.
              05  SQLN                  PIC S9(4) COMP VALUE +100.
              05  SQLD                  PIC S9(4) COMP.
              05  SQLVAR  OCCURS 100 TIMES.
                  10  SQLTYPE           PIC S9(4) COMP.
                  10  SQLLEN            PIC S9(4) COMP.
                  10  FILLER  REDEFINES SQLLEN.
                      15  SQLPREC       PIC X.
                      15  SQLSCALE      PIC X.
                  10  SQLDATA           PIC S9(9) COMP.
                  10  SQLIND            PIC S9(9) COMP.
                  10  SQLNAME-VARCHAR.
                      49  SQLNAME-LEN   PIC S9(4) COMP.
                      49  SQLNAME       PIC X(30).
          01  TABLE-NAME                PIC X(32).
          MOVE table-name TO TABLE-NAME.
          EXEC SQL
          DESCRIBE TABLE :TABLE-NAME INTO :SQLDA USING ANY
          END-EXEC
          PERFORM PRINT-NAMES SQLD TIMES.

See the previous example and consider the following.

Before the DESCRIBE statement is executed, you must set SQLN to the number of SQLVAR occurrences that are provided in the SQLDA. No information is returned in the SQLVARs if SQLD is set greater than SQLN, because in this case the SQLDA is not large enough (see the following for an explanation of how the SQLD is set).

CA Datacom/DB sets:

Assuming the object being described has n columns (and there are enough SQLVAR entries), values are assigned to the first n SQLVAR fields (listed in the following) to describe the object's columns. (When USING BOTH is specified, the SQLNAME field is used in a second set of n SQLVAR entries to return labels.)

SQLTYPE

A code for the data type of the column and if the column is nullable. See SQLDA (DESCRIBE or PREPARE INTO Statements) for a list of these codes.

SQLLEN

A length value depending on the data type of the column. See SQLDA (DESCRIBE or PREPARE INTO Statements) for possible values.

SQLDATA

A value of -1 indicates FOR BIT DATA.

SQLIND

Reserved.

SQLNAME

The unqualified name or label of the column, depending on the USING option specified.

Note: A string length of zero indicates that the column name or label does not exist.