ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzajp_5.4.0.1/rzajpequivsqlrpg.htm

315 lines
22 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Determine equivalent SQL and RPG/400 data types" />
<meta name="abstract" content="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." />
<meta name="description" content="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." />
<meta name="DC.subject" content="RPG/400 program, SQL data types, determining equivalent RPG, data type, determining equivalent, RPG/400, SQL data types, determining equivalent, numeric host variable, host variable, numeric, character, character host variable" />
<meta name="keywords" content="RPG/400 program, SQL data types, determining equivalent RPG, data type, determining equivalent, RPG/400, SQL data types, determining equivalent, numeric host variable, host variable, numeric, character, character host variable" />
<meta name="DC.Relation" scheme="URI" content="rzajprpg.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajprpgnotes.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rzajpequivsqlrpg" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Determine equivalent SQL and RPG/400 data types</title>
</head>
<body id="rzajpequivsqlrpg"><a name="rzajpequivsqlrpg"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Determine equivalent SQL and RPG/400 data types</h1>
<div><p>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.</p>
<div class="tablenoborder"><a name="rzajpequivsqlrpg__dtg"><!-- --></a><table cellpadding="4" cellspacing="0" summary="" id="rzajpequivsqlrpg__dtg" width="100%" frame="hsides" border="1" rules="all"><caption>Table 1. RPG/400<sup>®</sup> declarations mapped to typical
SQL data types</caption><thead align="left"><tr><th align="left" valign="bottom" width="14.444444444444443%" id="d0e79">RPG/400 data type</th>
<th align="left" valign="bottom" width="12.037037037037036%" id="d0e83">Col 43</th>
<th align="left" valign="bottom" width="10.185185185185185%" id="d0e85">Col 52</th>
<th align="left" valign="bottom" width="20.74074074074074%" id="d0e87">Other RPG/400 coding</th>
<th align="left" valign="bottom" width="12.962962962962962%" id="d0e92">SQLTYPE of host variable</th>
<th align="left" valign="bottom" width="15.185185185185185%" id="d0e94">SQLLEN of host variable</th>
<th align="left" valign="bottom" width="14.444444444444443%" id="d0e96">SQL data type</th>
</tr>
</thead>
<tbody><tr><td align="left" valign="top" width="14.444444444444443%" headers="d0e79 ">Data Structure subfield</td>
<td align="left" valign="top" width="12.037037037037036%" headers="d0e83 ">blank</td>
<td align="left" valign="top" width="10.185185185185185%" headers="d0e85 ">blank</td>
<td align="left" valign="top" width="20.74074074074074%" headers="d0e87 ">Length = n where n ≤ 256</td>
<td align="left" valign="top" width="12.962962962962962%" headers="d0e92 ">452</td>
<td align="left" valign="top" width="15.185185185185185%" headers="d0e94 ">n</td>
<td align="left" valign="top" width="14.444444444444443%" headers="d0e96 ">CHAR(n)</td>
</tr>
<tr><td align="left" valign="top" width="14.444444444444443%" headers="d0e79 ">Data structure (without subfields)</td>
<td align="left" valign="top" width="12.037037037037036%" headers="d0e83 ">n/a</td>
<td align="left" valign="top" width="10.185185185185185%" headers="d0e85 ">n/a</td>
<td align="left" valign="top" width="20.74074074074074%" headers="d0e87 ">Length = n where n ≤ 9999</td>
<td align="left" valign="top" width="12.962962962962962%" headers="d0e92 ">452</td>
<td align="left" valign="top" width="15.185185185185185%" headers="d0e94 ">n</td>
<td align="left" valign="top" width="14.444444444444443%" headers="d0e96 ">CHAR(n)</td>
</tr>
<tr><td align="left" valign="top" width="14.444444444444443%" headers="d0e79 ">Input field</td>
<td align="left" valign="top" width="12.037037037037036%" headers="d0e83 ">blank</td>
<td align="left" valign="top" width="10.185185185185185%" headers="d0e85 ">blank</td>
<td align="left" valign="top" width="20.74074074074074%" headers="d0e87 ">Length = n where n ≤ 256</td>
<td align="left" valign="top" width="12.962962962962962%" headers="d0e92 ">452</td>
<td align="left" valign="top" width="15.185185185185185%" headers="d0e94 ">n</td>
<td align="left" valign="top" width="14.444444444444443%" headers="d0e96 ">CHAR(n)</td>
</tr>
<tr><td align="left" valign="top" width="14.444444444444443%" headers="d0e79 ">Calculation result field</td>
<td align="left" valign="top" width="12.037037037037036%" headers="d0e83 ">n/a</td>
<td align="left" valign="top" width="10.185185185185185%" headers="d0e85 ">blank</td>
<td align="left" valign="top" width="20.74074074074074%" headers="d0e87 ">Length = n where n ≤ 256</td>
<td align="left" valign="top" width="12.962962962962962%" headers="d0e92 ">452</td>
<td align="left" valign="top" width="15.185185185185185%" headers="d0e94 ">n</td>
<td align="left" valign="top" width="14.444444444444443%" headers="d0e96 ">CHAR(n)</td>
</tr>
<tr><td align="left" valign="top" width="14.444444444444443%" headers="d0e79 ">Data Structure subfield</td>
<td align="left" valign="top" width="12.037037037037036%" headers="d0e83 ">B</td>
<td align="left" valign="top" width="10.185185185185185%" headers="d0e85 ">0</td>
<td align="left" valign="top" width="20.74074074074074%" headers="d0e87 ">Length = 2</td>
<td align="left" valign="top" width="12.962962962962962%" headers="d0e92 ">500</td>
<td align="left" valign="top" width="15.185185185185185%" headers="d0e94 ">2</td>
<td align="left" valign="top" width="14.444444444444443%" headers="d0e96 ">SMALLINT</td>
</tr>
<tr><td align="left" valign="top" width="14.444444444444443%" headers="d0e79 ">Data Structure subfield</td>
<td align="left" valign="top" width="12.037037037037036%" headers="d0e83 ">B</td>
<td align="left" valign="top" width="10.185185185185185%" headers="d0e85 ">0</td>
<td align="left" valign="top" width="20.74074074074074%" headers="d0e87 ">Length = 4</td>
<td align="left" valign="top" width="12.962962962962962%" headers="d0e92 ">496</td>
<td align="left" valign="top" width="15.185185185185185%" headers="d0e94 ">4</td>
<td align="left" valign="top" width="14.444444444444443%" headers="d0e96 ">INTEGER</td>
</tr>
<tr><td align="left" valign="top" width="14.444444444444443%" headers="d0e79 ">Data Structure subfield</td>
<td align="left" valign="top" width="12.037037037037036%" headers="d0e83 ">B</td>
<td align="left" valign="top" width="10.185185185185185%" headers="d0e85 ">1-4</td>
<td align="left" valign="top" width="20.74074074074074%" headers="d0e87 ">Length = 2</td>
<td align="left" valign="top" width="12.962962962962962%" headers="d0e92 ">500</td>
<td align="left" valign="top" width="15.185185185185185%" headers="d0e94 ">2</td>
<td align="left" valign="top" width="14.444444444444443%" headers="d0e96 ">DECIMAL(4,s) where s=column 52</td>
</tr>
<tr><td align="left" valign="top" width="14.444444444444443%" headers="d0e79 ">Data Structure subfield</td>
<td align="left" valign="top" width="12.037037037037036%" headers="d0e83 ">B</td>
<td align="left" valign="top" width="10.185185185185185%" headers="d0e85 ">1-9</td>
<td align="left" valign="top" width="20.74074074074074%" headers="d0e87 ">Length = 4</td>
<td align="left" valign="top" width="12.962962962962962%" headers="d0e92 ">496</td>
<td align="left" valign="top" width="15.185185185185185%" headers="d0e94 ">4</td>
<td align="left" valign="top" width="14.444444444444443%" headers="d0e96 ">DECIMAL(9,s) where s=column 52</td>
</tr>
<tr><td align="left" valign="top" width="14.444444444444443%" headers="d0e79 ">Data Structure subfield</td>
<td align="left" valign="top" width="12.037037037037036%" headers="d0e83 ">P</td>
<td align="left" valign="top" width="10.185185185185185%" headers="d0e85 ">0 to 9</td>
<td align="left" valign="top" width="20.74074074074074%" headers="d0e87 ">Length = n where n is 1 to 16</td>
<td align="left" valign="top" width="12.962962962962962%" headers="d0e92 ">484</td>
<td align="left" valign="top" width="15.185185185185185%" headers="d0e94 ">p in byte 1, s in byte 2</td>
<td align="left" valign="top" width="14.444444444444443%" headers="d0e96 ">DECIMAL(p,s) where p = n*2-1 and s = column
52</td>
</tr>
<tr><td align="left" valign="top" width="14.444444444444443%" headers="d0e79 ">Input field</td>
<td align="left" valign="top" width="12.037037037037036%" headers="d0e83 ">P</td>
<td align="left" valign="top" width="10.185185185185185%" headers="d0e85 ">0 to 9</td>
<td align="left" valign="top" width="20.74074074074074%" headers="d0e87 ">Length = n where n is 1 to 16</td>
<td align="left" valign="top" width="12.962962962962962%" headers="d0e92 ">484</td>
<td align="left" valign="top" width="15.185185185185185%" headers="d0e94 ">p in byte 1, s in byte 2</td>
<td align="left" valign="top" width="14.444444444444443%" headers="d0e96 ">DECIMAL(p,s) where p = n*2-1 and s = column
52</td>
</tr>
<tr><td align="left" valign="top" width="14.444444444444443%" headers="d0e79 ">Input field</td>
<td align="left" valign="top" width="12.037037037037036%" headers="d0e83 ">blank</td>
<td align="left" valign="top" width="10.185185185185185%" headers="d0e85 ">0 to 9</td>
<td align="left" valign="top" width="20.74074074074074%" headers="d0e87 ">Length = n where n is 1 to 30</td>
<td align="left" valign="top" width="12.962962962962962%" headers="d0e92 ">484</td>
<td align="left" valign="top" width="15.185185185185185%" headers="d0e94 ">p in byte 1, s in byte 2</td>
<td align="left" valign="top" width="14.444444444444443%" headers="d0e96 ">DECIMAL(p,s) where p = n and s = column 52</td>
</tr>
<tr><td align="left" valign="top" width="14.444444444444443%" headers="d0e79 ">Input field</td>
<td align="left" valign="top" width="12.037037037037036%" headers="d0e83 ">B</td>
<td align="left" valign="top" width="10.185185185185185%" headers="d0e85 ">0 to 4 if n = 2; 0 to 9 if n = 4</td>
<td align="left" valign="top" width="20.74074074074074%" headers="d0e87 ">Length = 2 or 4</td>
<td align="left" valign="top" width="12.962962962962962%" headers="d0e92 ">484</td>
<td align="left" valign="top" width="15.185185185185185%" headers="d0e94 ">p in byte 1, s in byte 2</td>
<td align="left" valign="top" width="14.444444444444443%" headers="d0e96 ">DECIMAL(p,s) where p=4 if n=2 or 9 if n=4
and s = column 52</td>
</tr>
<tr><td align="left" valign="top" width="14.444444444444443%" headers="d0e79 ">Calculation result field</td>
<td align="left" valign="top" width="12.037037037037036%" headers="d0e83 ">n/a</td>
<td align="left" valign="top" width="10.185185185185185%" headers="d0e85 ">0 to 9</td>
<td align="left" valign="top" width="20.74074074074074%" headers="d0e87 ">Length = n where n is 1 to 30</td>
<td align="left" valign="top" width="12.962962962962962%" headers="d0e92 ">484</td>
<td align="left" valign="top" width="15.185185185185185%" headers="d0e94 ">p in byte 1, s in byte 2</td>
<td align="left" valign="top" width="14.444444444444443%" headers="d0e96 ">DECIMAL(p,s) where p = n and s = column 52</td>
</tr>
<tr><td align="left" valign="top" width="14.444444444444443%" headers="d0e79 ">Data Structure subfield</td>
<td align="left" valign="top" width="12.037037037037036%" headers="d0e83 ">blank</td>
<td align="left" valign="top" width="10.185185185185185%" headers="d0e85 ">0 to 9</td>
<td align="left" valign="top" width="20.74074074074074%" headers="d0e87 ">Length = n where n is 1 to 30</td>
<td align="left" valign="top" width="12.962962962962962%" headers="d0e92 ">488</td>
<td align="left" valign="top" width="15.185185185185185%" headers="d0e94 ">p in byte 1, s in byte 2</td>
<td align="left" valign="top" width="14.444444444444443%" headers="d0e96 ">NUMERIC(p,s) where p = n and s = column 52</td>
</tr>
</tbody>
</table>
</div>
<div class="section"><p>Use the information in the following table to determine the RPG/400 data
type that is equivalent to a given SQL data type.</p>
</div>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="hsides" border="1" rules="all"><caption>Table 2. SQL data types mapped to typical RPG/400 declarations</caption><thead align="left"><tr><th align="left" valign="bottom" width="20%" id="d0e327">SQL data type</th>
<th align="left" valign="bottom" width="39.81481481481482%" id="d0e329">RPG/400 data type</th>
<th align="left" valign="bottom" width="40.18518518518518%" id="d0e333">Notes</th>
</tr>
</thead>
<tbody><tr><td align="left" valign="top" width="20%" headers="d0e327 ">SMALLINT</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">Subfield of a data structure. B in position
43, length must be 2 and 0 in position 52 of the subfield specification.</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">&nbsp;</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">INTEGER</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">Subfield of a data structure. B in position
43, length must be 4 and 0 in position 52 of the subfield specification.</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">&nbsp;</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">BIGINT</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">No exact equivalent</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">Use P in position 43 and 0 in position 52
of the subfield specification. </td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">DECIMAL</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">Subfield of a data structure. P in position
43 and 0 through 9 in position 52 of the subfield specification. <p>OR</p>
<p>Defined
as numeric and not a subfield of a data structure.</p>
</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">Maximum length of 16 (precision 30) and maximum
scale of 9.</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">NUMERIC</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">Subfield of the data structure. Blank in
position 43 and 0 through 9 in position 52 of the subfield</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">Maximum length of 30 (precision 30) and maximum
scale of 9.</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">FLOAT (single precision)</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">No exact equivalent</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">Use one of the alternative numeric data types
described above.</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">FLOAT (double precision)</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">No exact equivalent</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">Use one of the alternative numeric data types
described above.</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">CHAR(n)</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">Subfield of a data structure or input field.
Blank in positions 43 and 52 of the specification. <p>OR</p>
<p>Calculation
result field defined without decimal places.</p>
</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">n can be from 1 to 256.</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">CHAR(n)</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">Data structure name with no subfields in
the data structure.</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 "><em>n</em> can be from 1 to 9999.</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">VARCHAR(n)</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">No exact equivalent</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">Use a character host variable large enough
to contain the largest expected VARCHAR value.</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">CLOB</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">Not supported</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">Not supported</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">GRAPHIC(n)</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">Not supported</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">Not supported</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">VARGRAPHIC(n)</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">Not supported</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">Not supported</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">DBCLOB</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">Not supported</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">Not supported</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">BINARY</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">Not supported</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">Not supported</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">VARBINARY</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">Not supported</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">Not supported</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">BLOB</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">Not supported</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">Not supported</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">DATE</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">Subfield of a data structure. Blank in position
52 of the subfield specification. <p>OR</p>
<p>Field defined without decimal
places.</p>
</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">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.</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">TIME</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">Subfield of a data structure. Blank in position
52 of the subfield specification. <p>OR</p>
<p>Field defined without decimal
places.</p>
</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">Length must be at least 6; to include seconds,
length must be at least 8.</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">TIMESTAMP</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">Subfield of a data structure. Blank in position
52 of the subfield specification. <p>OR</p>
<p>Field defined without decimal
places.</p>
</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">Length must be at least 19. To include microseconds
at full precision, length must be 26. If length is less than 26, truncation
occurs on the microseconds part.</td>
</tr>
<tr><td align="left" valign="top" width="20%" headers="d0e327 ">DATALINK</td>
<td align="left" valign="top" width="39.81481481481482%" headers="d0e329 ">Not supported</td>
<td align="left" valign="top" width="40.18518518518518%" headers="d0e333 ">Not supported</td>
</tr>
<tr><td valign="top" width="20%" headers="d0e327 ">ROWID</td>
<td valign="top" width="39.81481481481482%" headers="d0e329 ">Not supported </td>
<td valign="top" width="40.18518518518518%" headers="d0e333 ">Not supported</td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="rzajprpgnotes.htm">Assignment rules in RPG/400 applications that use SQL</a></strong><br />
RPG/400 associates
precision and scale with all numeric types.</li>
</ul>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzajprpg.htm" title="The RPG/400 licensed program supports both RPG II and RPG III programs.">Code SQL statements in RPG/400 applications</a></div>
</div>
</div>
</body>
</html>