Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Google is your friend. I don't know DB2 (haven't used it in 20 years, but I Googled db2 integer in cobol and got 1,280,000 hits -- the second of which is an IBM manual that says
Quote: |
Table 17 helps you define host variables that receive output from the database. You can use the table to determine the COBOL data type that is equivalent to a given SQL data type. For example, if you retrieve TIMESTAMP data, you can use the table to define a suitable host variable in the program that receives the data value.
Table 17 shows direct conversions between DB2 data types and host data types. However, a number of DB2 data types are compatible. When you do assignments or comparisons of data that have compatible data types, DB2 does conversions between those compatible data types. See Table 1 for information on compatible data types.
Table 17. SQL data types mapped to typical COBOL declarations SQL data type COBOL data type Notes
SMALLINT
S9(4) COMP-4,
S9(4) COMP-5,
S9(4) COMP,
or S9(4) BINARY
INTEGER
S9(9) COMP-4,
S9(9) COMP-5,
S9(9) COMP,
or S9(9) BINARY
DECIMAL(p,s) or NUMERIC(p,s)
S9(p-s)V9(s) COMP-3 or
S9(p-s)V9(s)
PACKED-DECIMAL
DISPLAY SIGN
LEADING SEPARATE
# NATIONAL SIGN
# LEADING SEPARATE
p is precision; s is scale. 0<=s<=p<=31. If s=0, use S9(p)V or S9(p). If s=p, use SV9(s). If the COBOL compiler does not support 31–digit decimal numbers, no exact equivalent exists. Use COMP-2.
REAL or FLOAT (n)
COMP-1
1<=n<=21
DOUBLE PRECISION, DOUBLE or FLOAT (n)
COMP-2
22<=n<=53
CHAR(n) Fixed-length character string. For example,
01 VAR-NAME PIC X(n).
1<=n<=255
VARCHAR(n) Varying-length character string. For example,
01 VAR-NAME.
49 VAR-LEN PIC S9(4)
USAGE BINARY.
49 VAR-TEXT PIC X(n).
The inner variables must have a level of 49.
GRAPHIC(n) Fixed-length graphic string. For example,
01 VAR-NAME PIC G(n)
USAGE IS DISPLAY-1.
n refers to the number of double-byte characters, not to the number of bytes. 1<=n<=127
VARGRAPHIC(n) Varying-length graphic string. For example,
01 VAR-NAME.
49 VAR-LEN PIC S9(4)
USAGE BINARY.
49 VAR-TEXT PIC G(n)
USAGE IS DISPLAY-1.
n refers to the number of double-byte characters, not to the number of bytes.
The inner variables must have a level of 49.
DATE Fixed-length character string of length n. For example,
01 VAR-NAME PIC X(n).
If you are using a date exit routine, n is determined by that routine. Otherwise, n must be at least 10.
TIME Fixed-length character string of length n. For example,
01 VAR-NAME PIC X(n).
If you are using a time exit routine, n is determined by that routine. Otherwise, n must be at least 6; to include seconds, n must be at least 8.
TIMESTAMP Fixed-length character string of length of length n. For example,
01 VAR-NAME PIC X(n).
n must be at least 19. To include microseconds, n must be 26; if n is less than 26, truncation occurs on the microseconds part.
Result set locator
SQL TYPE IS
RESULT-SET-LOCATOR
Use this data type only for receiving result sets. Do not use this data type as a column type.
Table locator
SQL TYPE IS
TABLE LIKE
table-name
AS LOCATOR
Use this data type only in a user-defined function or stored procedure to receive rows of a transition table. Do not use this data type as a column type.
BLOB locator
USAGE IS SQL TYPE IS
BLOB-LOCATOR
Use this data type only to manipulate data in BLOB columns. Do not use this data type as a column type.
CLOB locator
USAGE IS SQL TYPE IS
CLOB-LOCATOR
Use this data type only to manipulate data in CLOB columns. Do not use this data type as a column type.
DBCLOB locator
USAGE IS SQL TYPE IS
DBCLOB-LOCATOR
Use this data type only to manipulate data in DBCLOB columns. Do not use this data type as a column type.
BLOB(n)
USAGE IS SQL TYPE IS
BLOB(n)
1≤n≤2147483647
CLOB(n)
USAGE IS SQL TYPE IS
CLOB(n)
1≤n≤2147483647
DBCLOB(n)
USAGE IS SQL TYPE IS
DBCLOB(n)
n is the number of double-byte characters. 1≤n≤1073741823
ROWID
SQL TYPE IS ROWID
Notes on COBOL variable declaration and usage
You should be aware of the following considerations when you declare COBOL host variables.
Controlling the CCSID
#IBM Enterprise COBOL for z/OS Version 3 Release 2 #or later, and the DB2 coprocessor for the COBOL compiler, support: #
#
* #The NATIONAL data type that is used for declaring Unicode values #in the UTF-16 format (that is, CCSID 1200)
* #The COBOL CODEPAGE compiler option that is used to specify the #default EBCDIC CCSID of character data items
You can use the NATIONAL data type and the CODEPAGE compiler #option to control the CCSID of the character host variables in your #application.
#For example, if you declare the host variable HV1 #as USAGE NATIONAL, then DB2 handles HV1 as if you had used this DECLARE #VARIABLE statement:
#
DECLARE :HV1 VARIABLE CCSID 1200
In #addition, the COBOL DB2 coprocessor uses the CCSID that is specified #in the CODEPAGE compiler option to indicate that all host variables #of character data type, other than NATIONAL, are specified with that #CCSID unless they are explicitly overridden by a DECLARE VARIABLE #statement.
Example: Assume that the COBOL CODEPAGE compiler option is specified as CODEPAGE(1234). The following code shows how you can control the CCSID:
DATA DIVISION.
01 HV1 PIC N(10) USAGE NATIONAL.
01 HV2 PIC X(20) USAGE DISPLAY.
01 HV3 PIC X(30) USAGE DISPLAY.
...
EXEC SQL
DECLARE :HV3 VARIABLE CCSID 1047
END-EXEC.
...
PROCEDURE DIVISION.
...
EXEC SQL
SELECT C1, C2, C3 INTO :HV1, :HV2, :HV3 FROM T1
END-EXEC.
The CCSID for each of these host variables is:
HV1
1200
HV2
1234
HV3
1047
SQL data types with no COBOL equivalent
If you are using a COBOL compiler that does not support decimal numbers of more than 18 digits, use one of the following data types to hold values of greater than 18 digits:
* A decimal variable with a precision less than or equal to 18, if the actual data values fit. If you retrieve a decimal value into a decimal variable with a scale that is less than the source column in the database, the fractional part of the value might be truncated.
* An integer or a floating-point variable, which converts the value. If you choose integer, you lose the fractional part of the number. If the decimal number might exceed the maximum value for an integer, or if you want to preserve a fractional value, you can use floating-point numbers. Floating-point numbers are approximations of real numbers. Therefore, when you assign a decimal number to a floating-point variable, the result might be different from the original number.
* A character-string host variable. Use the CHAR function to retrieve a decimal value into it. |
|
|