3. Embedded SQL for COBOL : COBOL Data Items and Data Types : Data Type Conversion : Runtime Numeric Type Conversion
 
Share this page                  
Runtime Numeric Type Conversion
The Ingres runtime system provides automatic data type conversion between numerictype values in the database and the forms system and numeric COBOL data items. It follows the standard COBOL type conversion rules. For example, if you assign the value in a scaled COMP3 data item (UNIX and Windows) or COMP1 data item (VMS) to an integervalued field in a form, the digits after the decimal point of the data item's value are truncated. Runtime errors are generated for overflow on conversion.
The preprocessor generates COBOL MOVE statements or calls Ingres convert routines that convert various COBOL data types. These can again be converted at runtime by Ingres based on the final value being set or retrieved. The standard COBOL data conversion rules hold for all these generated MOVE statements, with a potential loss of precision.
Floats are coerced to decimal types by Ingres at runtime.
The preprocessor uses temporary data items when moving values between numeric DISPLAY data items and Ingres objects. Depending on the PICTURE clause of the DISPLAY item shown below, these temporary data items are either:
COMP-3 or 4‑byte COMP-5 (UNIX or
COMP-2 or 4‑byte COMP (VMS)
The following table lists numeric DISPLAY items and temporary data items:
Numeric DISPLAY Item's Picture
Temporary Item's Data Type--UNIX and Windows
Temporary Item's Data Type--VMS
With scaling
PIC S9(9)V9(9) USAGE COMP-3
COMP-2
With > 10 numeric digits
PIC S9(9)V9(9) USAGE COMP-3
Not applicable
No scaling and 10 numeric digits
4‑byte COMP-5
4‑byte COMP
COMP-3 items used to set or receive Ingres values also require some runtime conversion. This is not true if you are setting or receiving decimal data. This is true for Micro Focus COBOL when float values are received into COMP‑3.
The preprocessor also generates code to use a temporary data item when Ingres data is to interact with a COBOL unscaled COMP data item whose picture string is exactly 10. Because a COBOL non‑scaled numeric item whose picture contains 10 or fewer digits is regarded as compatible with the Ingres integer type, ESQL/COBOL assigns such data to a temporary COBOL 4‑byte COMP‑5 data item to allow it to interact with Ingres integer data. Note that the range of the Ingres i4 type does not include all 10‑digit numbers. If you have 10‑digit numeric data outside the Ingres range, you should use a COMP‑3 (UNIX) or for VMS use COMP‑1 or COMP‑2 data item and choose the Ingres float type. Or with decimal you can use COMP‑3 and choose a decimal Ingres type.
You can use only COMP data items or items that get assigned to temporary 4‑byte COMP‑5 (UNIX) or COMP (VMS) data items to set the values of Ingres integer objects, such as table field row numbers. You can, however, use any numeric data items to set and retrieve numeric values in Ingres database tables or forms.
Windows and UNIX:
The Ingres money type is represented as a COMP‑3 data item.
VMS:
The Ingres money type is represented as an 8‑byte floating-point value, COMP‑2.
Recall that a COBOL non-scaled numeric item with a picture that contains 10 or fewer digits is regarded as compatible with the Ingres integer type. (For details, see Variable and Type Declarations in this chapter.) However, the VAX standard data type for an unscaled 10‑digit COMP item is a quadword (8 bytes). Therefore, ESQL/ COBOL assigns such data to a temporary COBOL 4‑byte COMP data item to allow it to interact with Ingres integer data. Note that the range of the Ingres integer4 type does not include all 10‑digit numbers.