The SQLDA Data Structure

The SQLDA data structure is shown below:

 01 SQLDA sync.
   05 SQLDAID            PIC X(8) VALUE "SQLDA  ".
   05 SQLDABC            PIC S9(9) COMP-5 value 0.
   05 SQLN               PIC S9(4) COMP-5 value 0.
   05 SQLD               PIC S9(9) COMP-5 value 0.
   05 SQLVAR OCCURS 0 to 1489 TIMES DEPENDING ON SQLD.
     10 SQLTYPE          PIC S9(4) COMP-5.
     10 SQLLEN           PIC S9(4) COMP-5.
 $IF P64 SET
     10 FILLER           PIC S9(9) COMP-5.
 $END
     10 SQLDATA          USAGE POINTER.
     10 SQLIND           USAGE POINTER.
     10 SQLNAME.
       15 SQLNAMEL       PIC S9(4) COMP-5.
       15 SQLNAMEC       PIC X(30).

The following table describes the contents of the SQLDA data structure.

Field Contains
SQLDAID The text string "SQLDA".
SQLDABC
  • 32-bit - The length of the SQLDA data structure (SQLN * 44 + 16)
  • 64-bit - The length of the SQLDA data structure (SQLN * 56 + 16)
SQLN Total number of SQLVAR entries allocated, equal to the number of input parameters or output columns.
SQLD Number of SQLVAR entries used.
SQLVAR SQLVAR is a group item, the number of occurrences of which depends on the value of SQLD.
SQLTYPE A number representing the data type of the column or host variable and indicating whether null values are allowed (see the table below for valid values).
SQLLEN Length of a value from a column. If the data is decimal (including money), SQLLEN is split into two parts: the first byte contains the precision; the second byte contains the scale.
FILLER For 64-bit environments, this is necessary to ensure that SQLDATA and SQLIND reside on 8-byte boundaries in memory, which is required for execution within a 64-bit environment.
SQLDATA For FETCH, OPEN, and EXECUTE, the address of the host variable (must be inserted by the application). For DESCRIBE and PREPARE, SQLDATA is not used.
SQLIND For FETCH, OPEN, and EXECUTE, the address of an associated indicator variable, if one exists. If the column does not permit a null value, the field is undefined. If the column permits a null value, SQLIND is set to -1 if the data value is null or to 0 if the data value is not null. For DESCRIBE and PREPARE, SQLIND is not used.
SQLNAME A group item containing the name and length of the column (not used for FETCH, OPEN or EXECUTE.
SQLNAMEL Length of the name column
SQLNAMEC Name of the column. For a derived column, this field contains the ASCII numeric literal value that represents the derived column's original position within the select list

Valid Values for SQLTYPE

Odd-numbered code values indicate that null values are allowed.

(1) - These types can be returned in COBOL by a PREPARE INTO or DESCRIBE statement.

(2) - These types can be set by an application using Dynamic SQL.

(3) - These types are supported for COBOL host variables.

(4) - For COBOL host variables to be recognized as being used for DATE/TIME columns, need to use SQL TYPE IS definition.

Code Data Type SQL Data Type COBOL Data Type
384/385 (1,2,3,4) 10-byte date string Date SQL TYPE IS DATE or PIC X(10)
386/387 (1,2,3,4) Date record Date SQL TYPE IS DATE-RECORD
388/389 (1,2,3,4) 8-byte time string Time SQL TYPE IS TIME or PIC X(8)
390/391 (1,2,3,4) Time record Time SQL TYPE IS TIME-RECORD
392/393 (1,2,3,4) 29-byte timestamp string Timestamp SQL TYPE IS TIMESTAMP or PIC X(29)
394/395 (1,2,3,4) Timestamp record Timestamp SQL TYPE IS TIMESTAMP-RECORD
396/397 DateTimeOffset DateTimeOffset PIC X(34)
398/399 DateTimeOffset record DateTimeOffset
01 NAME
  03 name-year   pic s9(4) comp-5.
   03 name-month  pic 9(4) comp-5.
   03 name-day    pic 9(4) comp-5.
   03 name-hour   pic 9(4) comp-5.
   03 name-min    pic 9(4) comp-5.
   03 name-sec    pic 9(4) comp-5.
   03 name-frac   pic 9(9) comp-5.
   03 name-tz-hr  pic s9(4) comp-5.
   03 name-tz-min pic s9(4) comp-5.
404/405 (1) Large variable length binary long varbinary 01 NAME

49 PIC LEN S9(9) COMP-5

49 PIC VAL X(n)

408/409 (1) Large variable length character long varchar 01 NAME

49 PIC LEN S9(9) COMP-5

49 PIC VAL X(n)

444/445 (1,2) Binary Binary PIC X(n)
446/447 (1,2) Variable length binary Varbinary 01 NAME

49 PIC LEN S9(4) COMP-5

49 PIC VAL X(n)

448/449 (1,2,3) Variable length character Varchar 01 NAME

49 PIC LEN S9(4) COMP-5

49 PIC VAL X(n)

452/453 (1,2,3) Fixed-length character Char PIC X(n)
480/481 (1,2,3) 8-byte floating point float or double COMP-2
482/483 (1,2) 4-byte floating point Real COMP-1
484/485 (1,2,3) Decimal decimal, numeric or bigint PIC S9(n)V9(m)

COMP-3

492/493 (1,2,3) 8-byte integer bigint PIC X(8) COMP-5
496/497 (1,2,3) 4-byte integer Integer PIC S9(9) COMP-5
500/501 (1,2,3) 2-byte integer Smallint PIC S9(4) COMP-5
502/503 (1,2) 1-byte integer Tinyint PIC S9(2) COMP-5
1080/1081 (1,2,3) Unicode character string Nchar PIC N(n) USAGE NATIONAL
1090/1091 (1,2,3) Unicode variable length string Nvarchar PIC N(n) USAGE NATIONAL
1100/1101 (1,2,3) Unicode large variable length string NTEXT PIC N(n) USAGE NATIONAL