Was this helpful?
How to Declare an SQLDA Record
To declare an SQLDA record, issue include sqlda or hard code the record as previously defined. This declaration must be in the Working-Storage Section of the COBOL Data Division but not in an SQL declare section because the preprocessor does not understand the special meaning of the fields of the SQLDA. When the SQLDA record is used, the preprocessor accepts any object name and assumes that the data item refers to a legally declared SQLDA record.
If a program requires an SQLDA with the same number of sqlvar elements as in the Ingres definition, it can accomplish this by including the following line in the Working-Storage Section:
EXEC SQL INCLUDE SQLDA END-EXEC.
and by including the following lines in the Procedure Division:
* Set the size of the SQLDA
MOVE 1024 to SQLN.
...
EXEC SQL DESCRIBE s1 INTO :SQLDA END-EXEC.
Note that the sqln is given an initial value of 1024.
If a program requires another SQLDA record or an SQLDA with a different number of sqlvar elements (not 1024), it can declare its own COBOL record as shown in the following examples.
Windows:
* In Working-Storage Section.
01 MY-SQLDA EXTERNAL.
  02 MY-SQID              PIC X(8).
  02 MY-SQSIZE            PIC S9(9) USAGE COMP-5.
  02 MY-VARS              PIC S9(4) USAGE COMP-5.
  02 RESULT-VARS          PIC S9(4) USAGE COMP-5.
  02 COLUMN-VARS          OCCURS 20 TIMES.
      03 COL-TYPE         PIC S9(4) USAGE COMP-5.
      03 COL-LEN          PIC S9(4) USAGE COMP-5.
      03 COL-ADDR         USAGE POINTER.
      03 COL-NULL         USAGE POINTER.
      03 COL-NAME.
          04 NAME-LEN     PIC S9(4) USAGE COMP-5.
          04 NAME-DAT     PIC X(34).

* In Procedure Division set the size of the SQLDA

MOVE 20 to MY-VARS.
UNIX:
* In Working-Storage Section.
01 MY-SQLDA EXTERNAL.
  02 MY-SQID              PIC X(8).
  02 MY-SQSIZE            PIC S9(9) USAGE COMP-5.
  02 MY-VARS              PIC S9(4) USAGE COMP-5.
  02 RESULT-VARS          PIC S9(4) USAGE COMP-5.
  02 COLUMN-VARS          OCCURS 20 TIMES.
      03 COL-TYPE         PIC S9(4) USAGE COMP-5.
      03 COL-LEN          PIC S9(4) USAGE COMP-5.
      03 COL-ADDR         USAGE POINTER.
      03 COL-NULL         USAGE POINTER.
      03 COL-NAME.
          04 NAME-LEN     PIC S9(4) USAGE COMP-5.
          04 NAME-DAT     PIC X(34).

* In Procedure Division set the size of the SQLDA

MOVE 20 to MY-VARS.
 
VMS:
* In Working-Storage Section.
01 MY-SQLDA EXTERNAL.
   02 MY-SQID           PIC X(8).
   02 MY-SQSIZE         PIC S9(9) USAGE COMP.
   02 MY-VARS           PIC S9(4) USAGE COMP.
   02 RESULT-VARS       PIC S9(4) USAGE COMP.
   02 COLUMN-VARS OCCURS 20 TIMES.
       03 COL-TYPE      PIC S9(4) USAGE COMP.
       03 COL-LEN       PIC S9(4) USAGE COMP.
       03 COL-ADDR      USAGE POINTER.
       03 COL-NULL      USAGE POINTER.
       03 COL-NAME.
            04 NAME-LEN PIC S9(4) USAGE COMP.
            04 NAME-DAT PIC X(34).

* In Procedure Division set the size of the SQLDA

MOVE 20 to MY-VARS.
In the above declarations, the names of the record components are not the same as those of the SQLDA record, but their layout is identical.
Last modified date: 08/28/2024