Determine data types of input host variables in REXX applications that use SQL

All data in REXX is in the form of strings.

The data type of input host variables (that is, host variables used in a 'USING host variable' clause in an EXECUTE or OPEN statement) is inferred by the database manager at run time from the contents of the variable according to the table below.

These rules define either numeric, character, or graphic values. A numeric value can be used as input to a numeric column of any type. A character value can be used as input to a character column of any type, or to a date, time, or timestamp column. A graphic value can be used as input to a graphic column of any type.

Table 1. Determine data types of host variables in REXX
Host variable contents Assumed data type SQL type code SQL type description
A number with neither decimal point nor exponent. It can have a leading plus or minus sign. Signed integers 496/497 INTEGER
A number that includes a decimal point, but no exponent,

or a number that does not include a decimal point or an exponent and is greater than 2147483647 or smaller than -2147483647.

It can have a leading plus or minus sign. m is the total number of digits in the number. n is the number of digits to the left of the decimal point (if any).

Packed decimal 484/485 DECIMAL(m,n)
A number that is in scientific or engineering notation (that is, followed immediately by an 'E' or 'e', an optional plus or minus sign, and a series of digits). It can have a leading plus or minus sign. Floating point 480/481 DOUBLE PRECISION
A string with leading and trailing apostrophes (') or quotation marks ("), which has length n after removing the two delimiters,

or a string with a leading X or x followed by a single quotation mark (') or quotation mark ("), and a trailing apostrophe (') or quotation mark ("). The string has a length of 2n after removing the X or x and the two delimiters. Each remaining pair of characters is the hexadecimal representation of a single character.

or a string of length n, which cannot be recognized as character, numeric, or graphic through other rules in this table

Varying-length character string 448/449 VARCHAR(n)
A string with a leading and trailing apostrophe (') or quotation marks (") preceded by: 1
  • A string that starts with a G, g, N or n. This is followed by a single quotation mark or quotation mark and a shift-out (x'0E'). This is followed by n graphic characters, each 2 characters long. The string must end with a shift-in (X'0F') and a single quotation mark or quotation mark (whichever the string started with).
  • A string with a leading GX, Gx, gX, or gx, followed by a single quotation mark or quotation mark and a shift-out (x'0E'). This is followed by n graphic characters, each 2 characters long. The string must end with a shift-in (X'0F') and a single quotation mark or quotation mark (whichever the string started with). The string has a length of 4n after removing the GX and the delimiters. Each remaining group of 4 characters is the hexadecimal representation of a single graphic character.
Varying-length graphic string 464/465 VARGRAPHIC(n)
Undefined Variable Variable for which a value has not been assigned None Data that is not valid was detected.
Note: The byte immediately following the leading apostrophe is a X'0E' shift-out, and the byte immediately preceding the trailing apostrophe is a X'0F' shift-in.