Supported SQL data types in COBOL embedded SQL applications
Certain predefined COBOL data types correspond to Db2® database column
types. You can use only these COBOL data types as host variables.
The following table shows the COBOL equivalent of each column type. When the precompiler finds a host variable declaration, it determines the appropriate SQL type value. The database manager uses this value to convert the data exchanged between the application and itself.
Not every possible data description for host variables is recognized. COBOL data items must be consistent with the ones described in the following table. If you use other data items, an error can result.
SQL Column Type1 | COBOL Data Type | SQL Column Type Description |
---|---|---|
SMALLINT
(500 or 501) |
01 name PIC S9(4) COMP-5. | 16-bit signed integer |
INTEGER
(496 or 497) |
01 name PIC S9(9) COMP-5. | 32-bit signed integer |
BIGINT
(492 or 493) |
01 name PIC S9(18) COMP-5. | 64-bit signed integer |
DECIMAL(p,s)
(484 or 485) |
01 name PIC S9(m)V9(n) COMP-3. | Packed decimal |
REAL2
(480 or 481) |
01 name USAGE IS COMP-1. | Single-precision floating point |
DOUBLE3
(480 or 481) |
01 name USAGE IS COMP-2. | Double-precision floating point |
CHAR(n)
(452 or 453) |
01 name PIC X(n). | Fixed-length character string |
VARCHAR(n)
(448 or 449) |
01 name.
49 length PIC S9(4) COMP-5. 49 name PIC X(n). 1<=n<=32 672 |
Variable-length character string |
LONG VARCHAR6
(456 or 457) |
01 name.
49 length PIC S9(4) COMP-5. 49 data PIC X(n). 32 673<=n<=32 700 |
Long variable-length character string |
CLOB(n)
(408 or 409) |
01 MY-CLOB USAGE IS SQL TYPE IS CLOB(n).
1<=n<=2 147 483 647 |
Large object variable-length character string |
CLOB locator variable4
(964 or 965) |
01 MY-CLOB-LOCATOR USAGE IS SQL TYPE IS CLOB-LOCATOR. | Identifies CLOB entities residing on the server |
CLOB file reference variable4
(920 or 921) |
01 MY-CLOB-FILE USAGE IS SQL TYPE IS CLOB-FILE. | Descriptor for file containing CLOB data |
BLOB(n)
(404 or 405) |
01 MY-BLOB USAGE IS SQL TYPE IS BLOB(n). 1<=n<=2 147 483 647 |
Large object variable-length binary string |
BLOB locator variable4
(960 or 961) |
01 MY-BLOB-LOCATOR USAGE IS SQL TYPE IS BLOB-LOCATOR. | Identifies BLOB entities residing on the server |
BLOB file reference variable4
(916 or 917) |
01 MY-BLOB-FILE USAGE IS SQL TYPE IS BLOB-FILE. | Descriptor for file containing BLOB data |
DATE
(384 or 385) |
01 identifier PIC X(10). | 10-byte character string |
TIME
(388 or 389) |
01 identifier PIC X(8). | 8-byte character string |
TIMESTAMP(p)
(392 or 393) |
01 identifier PIC X(p+20). 0<=p<=12
|
19 to 32 byte character string A 19 byte character string can be used, when p is 0. |
XML5
(988 or 989) |
01 name USAGE IS SQL TYPE IS XML
AS CLOB (size). |
XML value |
The following data types are only available in the DBCS environment.
SQL Column Type1 | COBOL Data Type | SQL Column Type Description |
---|---|---|
GRAPHIC(n)
(468 or 469) |
01 name PIC G(n) DISPLAY-1. | Fixed-length double-byte character string |
VARGRAPHIC(n)
(464 or 465) |
01 name.
49 length PIC S9(4) COMP-5. 49 name PIC G(n) DISPLAY-1. 1<=n<=16 336 |
Variable length double-byte character string with 2-byte string length indicator |
LONG VARGRAPHIC6
(472 or 473) |
01 name.
49 length PIC S9(4) COMP-5. 49 name PIC G(n) DISPLAY-1. 16 337<=n<=16 350 |
Variable length double-byte character string with 2-byte string length indicator |
DBCLOB(n)
(412 or 413) |
01 MY-DBCLOB USAGE IS SQL TYPE IS DBCLOB(n). 1<=n<=1 073 741 823 |
Large object variable-length double-byte character string with 4-byte string length indicator |
DBCLOB locator variable4
(968 or 969) |
01 MY-DBCLOB-LOCATOR USAGE IS SQL TYPE IS DBCLOB-LOCATOR. | Identifies DBCLOB entities residing on the server |
01 MY-DBCLOB-FILE USAGE IS SQL TYPE IS DBCLOB-FILE. | Descriptor for file containing DBCLOB data | |
Note:
|
The list of rules for supported COBOL data types are:
- PIC S9 and COMP-3/COMP-5 are required where shown.
- You can use level number 77 instead of 01 for all column types except VARCHAR, LONG VARCHAR, VARGRAPHIC, LONG VARGRAPHIC and all LOB variable types.
- Use the following rules when declaring host variables for DECIMAL(p,s)
column types. See the following sample:
01 identifier PIC S9(m)V9(n) COMP-3
- Use V to denote the decimal point.
- Values for n and m must be greater than or equal to 1.
- The value for n + m cannot exceed 31.
- The value for s equals the value for n.
- The value for p equals the value for n + m.
- The repetition factors (n) and (m) are optional.
The following examples are all valid:
01 identifier PIC S9(3)V COMP-3 01 identifier PIC SV9(3) COMP-3 01 identifier PIC S9V COMP-3 01 identifier PIC SV9 COMP-3
- PACKED-DECIMAL can be used instead of COMP-3.
- Arrays are not supported by the COBOL precompiler.