Vous êtes sur la page 1sur 5

DB2 Version 9 for Linux, UNIX, and Windows

Supported SQL data types in COBOL embedded SQL applications


Certain predefined COBOL data types correspond to DB2(R) database column types. Only these COBOL data types can be declared 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. Table 49. SQL Data Types Mapped to COBOL Declarations SQL Column Type SQL Column Type1 COBOL Data Type Description SMALLINT (500 or 501) INTEGER (496 or 497) BIGINT (492 or 493) DECIMAL(p,s) (484 or 485) REAL2 (480 or 481) DOUBLE3 (480 or 481) CHAR(n) (452 or 453) VARCHAR(n) (448 or 449) 01 name PIC S9(4) COMP-5. 01 name PIC S9(9) COMP-5. 01 name PIC S9(18) COMP-5. 01 name PIC S9(m)V9(n) COMP-3. 01 name USAGE IS COMP-1. 01 name USAGE IS COMP-2. 01 name PIC X(n). 01 name. 49 length PIC S9(4) COMP-5. 49 name PIC X(n). 1<=n<=32 672 LONG VARCHAR (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 16-bit signed integer 32-bit signed integer 64-bit signed integer Packed decimal Single-precision floating point Double-precision floating point Fixed-length character string Variable-length character string

Table 49. SQL Data Types Mapped to COBOL Declarations SQL Column Type SQL Column Type1 COBOL Data Type Description 01 MY-CLOB USAGE IS SQL TYPE IS Large object variableCLOB(n). CLOB(n) length character (408 or 409) string 1<=n<=2 147 483 647 CLOB locator variable4 (964 or 965) CLOB file reference variable4 (920 or 921) BLOB(n) (404 or 405) BLOB locator variable4 (960 or 961) BLOB file reference variable4 (916 or 917) DATE (384 or 385) TIME (388 or 389) TIMESTAMP (392 or 393) XML5 (988 or 989) Identifies CLOB 01 MY-CLOB-LOCATOR USAGE IS SQL entities residing on TYPE IS CLOB-LOCATOR. the server Descriptor for file 01 MY-CLOB-FILE USAGE IS SQL TYPE containing CLOB IS CLOB-FILE. data 01 MY-BLOB USAGE IS SQL TYPE IS BLOB(n). 1<=n<=2 147 483 647 Identifies BLOB 01 MY-BLOB-LOCATOR USAGE IS SQL entities residing on TYPE IS BLOB-LOCATOR. the server Descriptor for file 01 MY-BLOB-FILE USAGE IS SQL TYPE containing BLOB IS BLOB-FILE. data 01 identifier PIC X(10). 01 identifier PIC X(8). 01 identifier PIC X(26). 10-byte character string 8-byte character string 26-byte character string Large object variablelength binary string

01 name USAGE IS SQL TYPE IS XML AS XML value CLOB (size).

The following data types are only available in the DBCS environment. Table 50. SQL Data Types Mapped to COBOL Declarations SQL Column Type SQL Column Type1 COBOL Data Type Description GRAPHIC(n) (468 or 469) VARGRAPHIC(n) (464 or 465) 01 name PIC G(n) DISPLAY-1. 01 name. 49 length PIC S9(4) COMP-5. Fixed-length doublebyte character string Variable length double-byte character

Table 50. SQL Data Types Mapped to COBOL Declarations SQL Column Type SQL Column Type1 COBOL Data Type Description 49 name PIC G(n) DISPLAY-1. string with 2-byte string length indicator 1<=n<=16 336 LONG VARGRAPHIC (472 or 473) 01 name. 49 length PIC S9(4) COMP-5. 49 name PIC G(n) DISPLAY-1. 16 337<=n<=16 350 DBCLOB(n) (412 or 413) DBCLOB locator variable4 (968 or 969) DBCLOB file reference variable4 (924 or 925) Notes: 1. The first number under SQL Column Type indicates that an indicator variable is not provided, and the second number indicates that an indicator variable is provided. An indicator variable is needed to indicate NULL values, or to hold the length of a truncated string. These are the values that would appear in the SQLTYPE field of the SQLDA for these data types. 2. FLOAT(n) where 0 < n < 25 is a synonym for REAL. The difference between REAL and DOUBLE in the SQLDA is the length value (4 or 8). 3. The following SQL types are synonyms for DOUBLE: o FLOAT o FLOAT(n) where 24 < n < 54 is a synonym for DOUBLE. o DOUBLE PRECISION 4. This is not a column type but a host variable type. 5. The SQL_TYP_XML/SQL_TYP_NXML value is returned by DESCRIBE requests only. It cannot be used directly by the application to bind application resources to XML values. Variable length double-byte character string with 2-byte string length indicator

Large object variable01 MY-DBCLOB USAGE IS SQL TYPE IS length double-byte DBCLOB(n). character string with 4-byte string length 1<=n<=1 073 741 823 indicator 01 MY-DBCLOB-LOCATOR USAGE IS SQL TYPE IS DBCLOB-LOCATOR. 01 MY-DBCLOB-FILE USAGE IS SQL TYPE IS DBCLOB-FILE. Identifies DBCLOB entities residing on the server Descriptor for file containing DBCLOB data

The following are additional rules for supported COBOL data types:
y

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 o o o o o o o o o

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 01 01 01 identifier identifier identifier identifier PIC PIC PIC PIC S9(3)V COMP-3 SV9(3) COMP-3 S9V COMP-3 SV9 COMP-3

PACKED-DECIMAL can be used instead of COMP-3. Arrays are not supported by the COBOL precompiler.
o

Related concepts
y y y y y

Host variable names in COBOL Declare section for host variables in COBOL embedded SQL applications Null-indicator variables and null or truncation indicator variable tables in COBOL embedded SQL applications Example: SQL declare section template for COBOL embedded SQL applications Example: Referencing XML host variables in embedded SQL applications

Related tasks
y y

Executing XQuery expressions in embedded SQL applications Declaring XML host variables in embedded SQL applications

Related reference
y

COBOL samples Reference topic This topic is part of:

Developing Embedded SQL Applications

Feedback

Last updated 2006-10-27 http://publib.boulder.ibm.com/infocenter/db2luw/v9/topic/com.ibm.db2.udb.apdv.embed.doc/do c/r0006152.htm

Vous aimerez peut-être aussi