What You Declare
Within an SQL declare section, you specify the name, level, and data type of host variables using standard COBOL data declarative statements and observing these guidelines:
A CA IDMS extension of the SQL standard allows level numbers in the range of 02 to 49.
Equivalent Column Data Types
All CA IDMS data types can be supported in a COBOL program.
This table shows types of COBOL host variables and the equivalent CA IDMS table column data types:
COBOL PICTURE and USAGE clause |
CA IDMS data type |
---|---|
PIC X(n) USAGE DISPLAY |
CHAR(n) |
01 name 49 name-LEN PIC S9(4) COMP 49 name-TEXT PIC X(n) |
VARCHAR(n) |
PIC S9(p-s)V9(s) USAGE COMP-3 |
DECIMAL(p,s) |
PIC 9(p-s)V9(s) USAGE COMP-3 |
UNSIGNED DECIMAL(p,s)1 |
USAGE COMP-2 |
DOUBLE PRECISION |
USAGE COMP-1 |
REAL |
USAGE COMP-1 |
FLOAT |
PIC S9(n) USAGE COMP (where n<5) |
SMALLINT |
PIC S9(n) USAGE COMP (where n>4 and n<10) |
INTEGER |
PIC S9(n) USAGE COMP (where n>9) |
LONGINT or BIGINT |
PIC S9(p-s)V9(s) USAGE DISPLAY |
NUMERIC(p,s) |
PIC 9(p-s)V9(s) USAGE DISPLAY |
UNSIGNED NUMERIC(p,s)1 |
PIC X(n) USAGE SQLBIN |
BINARY(n) |
PIC G(n) USAGE DISPLAY-1 |
GRAPHIC(n)1 |
01 name 49 name-LEN PIC S9(4) COMP 49 name-TEXT PIC G(n) DISPLAY-1 |
VARGRAPHIC(n)1 |
PIC X(10) USAGE DISPLAY |
DATE |
PIC X(8) USAGE DISPLAY |
TIME |
PIC X(26) USAGE DISPLAY |
TIMESTAMP |
PIC X(8) USAGE SQLBIN |
TID1 |
Note: 1This data type is a CA IDMS extension of the SQL standard. For more information about CA IDMS data types, see the CA IDMS SQL Reference Guide.
Host Variable Declaration Example
In this example, the SQL declare section defines host variables, including one indicator variable, using standard COBOL data declarations. The example is annotated to show the equivalent column data type for each variable and to identify an indicator variable:
WORKING-STORAGE SECTION. . . . EXEC SQL BEGIN DECLARE SECTION END-EXEC. 01 EMP-ID PIC S9(8) USAGE COMP. ◄─ INTEGER 01 EMP-LNAME PIC X(20). ◄─ CHARACTER 01 SALARY-AMOUNT PIC S9(6)V(2) USAGE COMP-3. ◄─ DECIMAL 01 PROMO-DATE PIC X(10). ◄─ DATE 01 PROMO-DATE-I PIC S9(4) USAGE COMP. ◄─ Indicator variable EXEC SQL END DECLARE SECTION END-EXEC.
Declaring an indicator variable
An indicator variable must be either a 2 or 4 byte computational (binary) data type. In the example above, PROMO-DATE-I is a valid indicator variable.
SQLIND data type
You can declare an indicator variable with the data type SQLIND:
05 PROMO_DATE PIC X(10). ◄─ DATE 05 PROMO_DATE_I SQLIND. ◄─ Indicator variable
The precompiler will substitute PIC S9(8) USAGE COMP in the output source.
The SQLIND data type is primarily for use within bulk structure definitions. In other cases its use is optional.
Allowable Host Variable Definitions
A host variable definition may contain:
Within a bulk structure definition, the occurs clause is allowed only on the second-level group element. The following subclauses are also supported but only on the second level group element of a bulk structure:
Note: The DEPENDING ON variable is not used in determining the number of rows in the bulk structure.
(1 This support is a CA IDMS extension of the SQL standard.)
Copyright © 2013 CA.
All rights reserved.
|
|