Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
What COBOL datatypes are compatible with Integer in DB2

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
Mrspredeep

New User


Joined: 30 Jun 2010
Posts: 28
Location: USA

PostPosted: Tue Aug 17, 2010 10:12 pm    Post subject: What COBOL datatypes are compatible with Integer in DB2
Reply with quote

Hi

What COBOL datatypes are compatible with Integer in DB2?

So far, I have tried:
S9(9) COMP3
S9(9) COMP

I have also heard that the Sign plays a crucial part, so 9(9) comp might not work.
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8165
Location: East Dubuque, Illinois, USA

PostPosted: Tue Aug 17, 2010 10:22 pm    Post subject:
Reply with quote

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&#8804;n&#8804;2147483647
CLOB(n)

USAGE IS SQL TYPE IS
CLOB(n)

1&#8804;n&#8804;2147483647
DBCLOB(n)

USAGE IS SQL TYPE IS
DBCLOB(n)

n is the number of double-byte characters. 1&#8804;n&#8804;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.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm
No new posts Assembler Macro Copybook converted to... Ziquilix PL/I & Assembler 4 Tue Sep 26, 2017 3:07 am
This topic is locked: you cannot edit posts or make replies. Extract all "IF" Statements... Adarsh Damodaran CLIST & REXX 1 Wed Sep 06, 2017 9:28 am
No new posts ALPHABETIC check in COBOL vidyaa COBOL Programming 8 Thu Aug 17, 2017 7:13 pm
No new posts XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us