Determine equivalent SQL and PL/I data types

The precompiler determines the base SQLTYPE and SQLLEN of host variables based on the following table.

If a host variable appears with an indicator variable, the SQLTYPE is the base SQLTYPE plus one.

Table 1. PL/I declarations mapped to typical SQL data types
PL/I data type SQLTYPE of host variable SQLLEN of host variable SQL data type
BIN FIXED(p) where p is in the range 1 to 15 500 2 SMALLINT
BIN FIXED(p) where p is in the range 16 to 31 496 4 INTEGER
DEC FIXED(p,s) 484 p in byte 1, s in byte 2 DECIMAL(p,s)
BIN FLOAT(p) p is in the range 1 to 24 480 4 FLOAT (single precision)
BIN FLOAT(p) p is in the range 25 to 53 480 8 FLOAT (double precision)
DEC FLOAT(m) m is in the range 1 to 7 480 4 FLOAT (single precision)
DEC FLOAT(m) m is in the range 8 to 16 480 8 FLOAT (double precision)
PICTURE picture string (numeric) 488 p in byte 1, s in byte 2 NUMERIC (p,s)
PICTURE picture string (sign leading separate) 504 p in byte 1, s in byte 2 No exact equivalent, use NUMERIC(p,s).
CHAR(n) 452 n CHAR(n)
CHAR(n) VARYING 448 n VARCHAR(n)

The following table can be used to determine the PL/I data type that is equivalent to a given SQL data type.

Table 2. SQL data types mapped to typical PL/I declarations
SQL data type PL/I equivalent Notes
SMALLINT BIN FIXED(p) p is a positive integer from 1 to 15.
INTEGER BIN FIXED(p) p is a positive integer from 16 to 31.
BIGINT No exact equivalent Use DEC FIXED(18).
DECIMAL(p,s) or NUMERIC(p,s) DEC FIXED(p) or DEC FIXED(p,s) or PICTURE picture-string s (the scale factor) and p (the precision) are positive integers. p is a positive integer from 1 to 31. s is a positive integer from 0 to p.
FLOAT (single precision) BIN FLOAT(p) or DEC FLOAT(m) p is a positive integer from 1 to 24.

m is a positive integer from 1 to 7.

FLOAT (double precision) BIN FLOAT(p) or DEC FLOAT(m) p is a positive integer from 25 to 53.

m is a positive integer from 8 to 16.

CHAR(n) CHAR(n) n is a positive integer from 1 to 32766.
VARCHAR(n) CHAR(n) VARYING n is a positive integer from 1 to 32740.
CLOB None Use SQL TYPE IS to declare a CLOB.
GRAPHIC(n) Not supported Not supported.
VARGRAPHIC(n) Not supported Not supported.
DBCLOB Not supported Not supported
BINARY None Use SQL TYPE IS to declare a BINARY.
VARBINARY None Use SQL TYPE IS to declare a VARBINARY.
BLOB None Use SQL TYPE IS to declare a BLOB.
DATE CHAR(n) If the format is *USA, *JIS, *EUR, or *ISO, n must be at least 10 characters. If the format is *YMD, *DMY, or *MDY, n must be at least 8 characters. If the format is *JUL, n must be at least 6 characters.
TIME CHAR(n) n must be at least 6; to include seconds, n must be at least 8.
TIMESTAMP CHAR(n) n must be at least 19. To include microseconds at full precision, n must be 26; if n is less than 26, truncation occurs on the microseconds part.
DATALINK Not supported Not supported
ROWID None Use SQL TYPE IS to declare a ROWID.