Passing the data type of an input data type to Db2 for REXX programs

In certain situations, you should tell Db2 the data type to use for input data in a REXX program. For example, if you are assigning or comparing input data to columns of type SMALLINT, CHAR, or GRAPHIC, you should tell Db2 to use those data types.

About this task

Db2 does not assign data types of SMALLINT, CHAR, or GRAPHIC to input data. If you assign or compare this data to columns of type SMALLINT, CHAR, or GRAPHIC, Db2 must do more work than if the data types of the input data and columns match.

Procedure

To pass the data type of an input data type to Db2 for REXX programs:

Use an SQLDA.

Examples

Example: Specifying CHAR as an input data type
Suppose that you want to tell Db2 that the data with which you update the MIDINIT column of the EMP table is of type CHAR, rather than VARCHAR. You need to set up an SQLDA that contains a description of a CHAR column, and then prepare and execute the UPDATE statement using that SQLDA, as shown in the following example.
INSQLDA.SQLD = 1                /* SQLDA contains one variable   */
INSQLDA.1.SQLTYPE = 453         /* Type of the variable is CHAR, */
                                /* and the value can be null     */
INSQLDA.1.SQLLEN  = 1           /* Length of the variable is 1   */
INSQLDA.1.SQLDATA = 'H'         /* Value in variable is H        */
INSQLDA.1.SQLIND  = 0           /* Input variable is not null    */
SQLSTMT="UPDATE EMP" ,
  "SET MIDINIT = ?"  ,
  "WHERE EMPNO = '000200'"
"EXECSQL PREPARE S100 FROM :SQLSTMT"
"EXECSQL EXECUTE S100 USING DESCRIPTOR :INSQLDA"
Example: specifying the input data type as DECIMAL with precision and scale
Suppose that you want to tell Db2 that the data is of type DECIMAL with precision and nonzero scale. You need to set up an SQLDA that contains a description of a DECIMAL column, as shown in the following example.
INSQLDA.SQLD = 1                          /* SQLDA contains one variable  */
INSQLDA.1.SQLTYPE = 484                   /* Type of variable is DECIMAL  */
INSQLDA.1.SQLLEN.SQLPRECISION = 18        /* Precision of variable is 18  */
INSQLDA.1.SQLLEN.SQLSCALE = 8             /* Scale of variable is 8       */
INSQLDA.1.SQLDATA = 9876543210.87654321   /* Value in variable            */