SQL/MP Programming Manual for COBOL

Host Variables
HP NonStop SQL/MP Programming Manual for COBOL529758-003
2-5
Using Corresponding SQL and COBOL Data Types
Data Conversion
SQL/MP performs the conversion between SQL and COBOL data types:
When a host variable serves as an input variable (supplies a value to the
database), SQL/MP first converts the value that the variable contains to a
compatible SQL data type and then uses the value in the SQL operation.
When a host variable serves as an output variable (receives a value from a
database), SQL/MP converts the value to the data type of the host variable.
SQL/MP supports conversion within character types and numeric types, not between
character and numeric types.
For conversion between character strings of different lengths, SQL/MP pads the
receiving string on the right with blanks as necessary. If the receiving string is too
small, SQL/MP truncates the right part of the longer string and generates a warning
code in the SQLCODE variable.
If an input value is too large for the SQL column, SQL/MP reports error 8300 (file-
system error encountered). If you are using the SQLCA_DISPLAY2_ procedure to
display error messages, the specific file-system error (1031) is also returned.
For numeric type conversion, SQL/MP converts data between signed and unsigned
types and between types with different precisions. Scales and precisions can be
different. Decimal variables can have different sign placements.
CAST Function
The CAST function allows you to convert a parameter from one data type to another
data type (character and numeric data types only) in dynamic SQL statements. For
information about the CAST function, see the SQL/MP Reference Manual.
Note. To retrieve floating-point columns, you must declare all the required host variables with
corresponding data types supported by COBOL. (Floating-point columns will be handled during
data type conversion.) For example, you must declare numeric host variables, like REAL,
FLOAT, and DOUBLE PRECISION, as a numeric data type supported by COBOL.
Ensure that the actual values in a floating-point column can be converted without resulting in
an overflow.
Note. For systems running J06.09 and later J-series RVUs, H06.20 and later RVUs, or
G06.32 and later G-series RVUs, the SQL integer data types is mapped to the
corresponding COBOL data types with the COMP-5 option when the external DEFINE
=_SQL_MAPTO_COBOL_COMP5 is present in the system.
Note. For optimal performance, declare host variables with the same data types and lengths
as their respective columns in SQL statements. This programming practice minimizes the data
conversions performed by SQL/MP and, therefore, can improve the performance of your
program.