3. Embedded SQL for COBOL : COBOL Data Items and Data Types : Data Type Conversion
 
Share this page                  
Data Type Conversion
A COBOL data item must be compatible with the Ingres value it represents. Numeric Ingres values can be set by and retrieved into COBOL numeric and numeric edited items, and Ingres character values can be set by and retrieved into COBOL character data items, that is, alphabetic, alphanumeric, and alphanumeric edited items.
Data type conversion occurs automatically for different numeric types such as from floating-point Ingres database column values into integer (COMP) COBOL data items, and for different length character strings, such as from varyinglength Ingres character fields into COBOL alphabetic and alphanumeric data items.
Ingres does not automatically convert between numeric and character types, such as from Ingres integer fields into COBOL alphanumeric data items. You must use the Ingres type conversion functions, the Ingres ascii function, or the COBOL STRING statement to effect such conversions.
The following table shows the default type compatibility for each Ingres data type in UNIX and VMS. Note that some COBOL types are omitted from the table because they do not exactly match an Ingres type. Use of those types necessitates some runtime conversion, which may possibly result in some loss of precision.
Windows and UNIX:
There is no exact match for float, so use COMP3.
Ingres types and their corresponding COBOL data types are listed in the following table:
Ingres Type
UNIX and Windows COBOL Types
VMS COBOL Type
char(N)
PIC X(N).
PIC X(N).
varchar(N)
PIC X(N).
PIC X(N).
integer1
PIC S9(2) USAGE COMP.
PIC S9(2) USAGE COMP.
smallint
PIC S9(4) USAGE COMP.
PIC S9(4) USAGE COMP.
integer
PIC S9(9) USAGE COMP.
PIC S9(9) USAGE COMP.
bigint
PIC S9(18) USAGE COMP*
PIC S9(18) USAGE COMP*
long varchar
PIC X(N).
PIC X(N).
float4
PIC S9(10)V9(8) USAGE COMP-3.
USAGE COMP-1.
float
PIC S9(10)V9(8) USAGE COMP-3.
USAGE COMP-2.
date
PIC X(25).
PIC X(25).
money
PIC S9(10)V9(8) USAGE COMP-3.
USAGE COMP-2.
table_key
PIC X(8).
PIC X(8).
object_key
PIC X(16).
PIC X(16).
decimal
PICS9(P-S)V(S) USAGE COMP-3.
PICS9(P-S)V(S) USAGE COMP-3.
*This type may not map to 8-byte integers with some COBOL compilers.
Note that Ingres stores decimal as signed. Thus, use a signed decimal variable if it interacts with an Ingres decimal type. Also, Ingres allows a maximum precision of 39 while COBOL allows only 18.