SQL/MP Programming Manual for COBOL85
Host Variables
HP NonStop SQL/MP Programming Manual for COBOL85—429326-004
2-5
Using Corresponding SQL and COBOL Data Types
Data Conversion
SQL/MP performs the conversion between SQL and COBOL data types as follows:
•
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. 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.