The precompiler determines the base SQLTYPE and SQLLEN of host variables according to the following table. If a host variable appears with an indicator variable, the SQLTYPE is the base SQLTYPE plus one.
RPG data type | RPG coding | SQLTYPE of host variable | SQLLEN of host variable | SQL data type |
---|---|---|---|---|
Data structure (without subfields) | Length = n where n ≤ 32766. | 452 | n | CHAR(n) |
Zoned data |
|
488 | p in byte 1, s in byte 2 | NUMERIC(p, s) where p is the number of digits and s is the number of decimal places |
Packed data |
|
484 | p in byte 1, s in byte 2 | DECIMAL(p, s) where p is the number of digits and s is the number of decimal places |
2-byte binary with zero decimal positions |
|
500 | 2 | SMALLINT |
4-byte binary with zero decimal positions |
|
496 | 4 | INTEGER |
2-byte integer |
|
500 | 2 | SMALLINT |
4-byte integer |
|
496 | 4 | INTEGER |
8-byte integer |
|
492 | 8 | BIGINT |
short float | Data type = F, length = 4. | 480 | 4 | FLOAT (single precision) |
long float | Data type = F, length = 8. | 480 | 8 | FLOAT (double precision) |
Character | Data type = A or blank, decimal positions blank, length between 1 and 32766. | 452 | n | CHAR (n) where n is the length |
Character varying length greater than 254 | Data type = A or blank, decimal positions blank, VARYING keyword on Definition specification or format *VAR on Input specification. | 448 | n | VARCHAR (n) where n is the length |
Character varying length between 1 and 254 | Data type = A or blank, decimal positions blank, VARYING keyword on Definition specification or format *VAR on Input specification. | 456 | n | VARCHAR (n) where n is the length |
graphic |
|
468 | m | GRAPHIC(m) where m = n or m = b/2 |
varying graphic |
|
464 | m | VARGRAPHIC(m) where m = n or m = (b-2)/2 |
UCS-2 |
|
468 | m | GRAPHIC(m) with CCSID 13488 where m = n or m = b/2 |
varying UCS-2 |
|
464 | m | VARGRAPHIC(m) with CCSID 13488 where m = n or m = b/2 |
Date |
|
384 | n | DATE DATFMT(f) DATSEP(s)1 |
Time |
|
388 | n | TIME TIMFMT(f) TIMSEP(s)1 |
Timestamp | Data type Z. | 392 | n | TIMESTAMP |
1SQL creates the date/time subfield using the DATE/TIME format specified on the CRTSQLRPGI command. The conversion to the host variable DATE/TIME format occurs when the mapping is done between the host variables and the SQL-generated subfields. |
The following table can be used to determine the RPG data type that is equivalent to a given SQL data type.
SQL data type | RPG data type | Notes |
---|---|---|
SMALLINT | Definition specification. I in position 40,
length must be 5 and 0 in position 42. OR Definition specification. B in position 40, length must be ≤ 4 and 0 in position 42. |
|
INTEGER | Definition specification. I in position 40,
length must be 10 and 0 in position 42. OR Definition specification. B in position 40, length must be ≤ 9 and ≥ 5 and 0 in position 42. |
|
BIGINT | Definition specification. I in position 40, length must be 20 and 0 in position 42. | |
DECIMAL | Definition specification. P in position 40
or blank in position 40 for a non-subfield, 0 through 30 in position 41,42. OR Defined as numeric on non-definition specification. |
Maximum length of 16 (precision 30) and maximum scale of 30. |
NUMERIC | Definition specification. S in position 40 or blank in position 40 for a subfield, 0 through 30 in position 41,42. | Maximum length of 30 (precision 30) and maximum scale of 30. |
FLOAT (single precision) | Definition specification. F in position 40, length must be 4. | |
FLOAT (double precision) | Definition specification. F in position 40, length must be 8. | |
CHAR(n) | Definition specification. A or blank in positions
40 and blanks in position 41,42. OR Input field defined
without decimal places.
OR Calculation result field defined without decimal places. |
n can be from 1 to 32766. |
CHAR(n) | Data structure name with no subfields in the data structure. | n can be from 1 to 32766. |
VARCHAR(n) | Definition specification. A or blank in position 40 and VARYING in positions 44-80. | n can be from 1 to 32740. |
CLOB | Not supported | Use SQLTYPE keyword to declare a CLOB. |
GRAPHIC(n) | Definition specification. G in position 40. OR Input field defined with G in position 36. |
n can be 1 to 16383. |
VARGRAPHIC(n) | Definition specification. G in position 40 and VARYING in positions 44-80. | n can be from 1 to 16370. |
DBCLOB | Not supported | Use SQLTYPE keyword to declare a DBCLOB. |
BINARY | Not supported | Use SQLTYPE keyword to declare a BINARY. |
VARBINARY | Not supported | Use SQLTYPE keyword to declare a VARBINARY. |
BLOB | Not supported | Use SQLTYPE keyword to declare a BLOB. |
DATE | A character field OR Definition
specification with a D in position 40.
OR Input field defined with D in position 36. |
If the format is *USA, *JIS, *EUR, or *ISO, the length must be at least 10. If the format is *YMD, *DMY, or *MDY, the length must be at least 8. If the format is *JUL, the length must be at least 6. |
TIME | A character field OR Definition
specification with a T in position 40.
OR Input field defined with T in position 36. |
Length must be at least 6; to include seconds, length must be at least 8. |
TIMESTAMP | A character field OR Definition
specification with a Z in position 40.
OR Input field defined with Z in position 36. |
Length must be at least 19; to include microseconds, length must be at least 26. If length is less than 26, truncation occurs on the microsecond part. |
DATALINK | Not supported | |
ROWID | Not supported | Use SQLTYPE keyword to declare a ROWID. |