ibm-information-center/dist/eclipse/plugins/i5OS.ic.db2_5.4.0.1/rbafzmstdeclvar.htm

179 lines
9.4 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 xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="dc.language" scheme="rfc1766" 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. -->
<meta name="dc.date" scheme="iso8601" content="2005-09-19" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<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="keywords" content="DECLARE VARIABLE statement, DECLARE VARIABLE,
SQL statements, host variable, CCSID clause, in DECLARE VARIABLE statement,
host-variable, FOR BIT DATA clause, FOR SBCS DATA clause, FOR MIXED DATA clause" />
<title>DECLARE VARIABLE</title>
<link rel="stylesheet" type="text/css" href="ibmidwb.css" />
<link rel="stylesheet" type="text/css" href="ic.css" />
</head>
<body>
<a id="Top_Of_Page" name="Top_Of_Page"></a><!-- Java sync-link -->
<script language = "Javascript" src = "../rzahg/synch.js" type="text/javascript"></script>
<a name="declvar"></a>
<h2 id="declvar"><a href="rbafzmst02.htm#ToC_1001">DECLARE VARIABLE</a></h2><a id="idx2350" name="idx2350"></a><a id="idx2351" name="idx2351"></a><a id="idx2352" name="idx2352"></a>
<a name="dclvar"></a>
<p id="dclvar">The DECLARE VARIABLE statement is used to assign a subtype
or CCSID other than the default to a host variable.</p>
<a name="wq1439"></a>
<h3 id="wq1439"><a href="rbafzmst02.htm#ToC_1002">Invocation</a></h3><a id="idx2353" name="idx2353"></a>
<p>This statement can only be embedded in an application program. It is not
an executable statement. It must not be specified in Java&trade; or
REXX.</p>
<a name="wq1440"></a>
<h3 id="wq1440"><a href="rbafzmst02.htm#ToC_1003">Authorization</a></h3>
<p>None required.</p>
<a name="wq1441"></a>
<h3 id="wq1441"><a href="rbafzmst02.htm#ToC_1004">Syntax</a></h3>
<a href="rbafzmstdeclvar.htm#synsdvar"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn325.htm"
border="0" /></span><a href="#skipsyn-324"><img src="c.gif" alt="Skip visual syntax diagram"
border="0" /></a> .-,-------------.
V |
>>-DECLARE----<span class="italic">host-variable</span>-+--VARIABLE------------------------->
>--+--------------------+-------------------------------------->&lt;
+-+-FOR SBCS DATA--+-+
| +-FOR MIXED DATA-+ |
| +-CCSID--<span class="italic">integer</span>-+ |
| '-FOR BIT DATA---' |
'-+-DATE------+------'
+-TIME------+
'-TIMESTAMP-'
</pre>
<a name="skipsyn-324" id="skipsyn-324"></a>
<a name="synsdvar"></a>
<h3 id="synsdvar"><a href="rbafzmst02.htm#ToC_1005">Description</a></h3>
<dl class="parml">
<dt class="bold"><var class="pv">host-variable</var> </dt><a id="idx2354" name="idx2354"></a>
<dd>Names a character or graphic-string host variable defined in the program.
An indicator variable cannot be specified for the host-variable. The host-variable
definition may either precede or follow a DECLARE VARIABLE statement that
refers to that variable.
</dd>
<dt class="bold">FOR BIT DATA </dt><a id="idx2355" name="idx2355"></a>
<dd>Specifies that the values of the host-variable are not associated with
a coded character set and, therefore, are never converted. The CCSID of a
FOR BIT DATA host variable is 65535. FOR BIT DATA cannot be specified for
graphic host-variables.
</dd>
<dt class="bold">FOR SBCS DATA </dt><a id="idx2356" name="idx2356"></a>
<dd>Specifies that the values of the host variable contain SBCS (single-byte
character set) data. FOR SBCS DATA is the default if the CCSID attribute of
the job at the application requester is not DBCS-capable or if the length
of the host variable is less than 4. The CCSID of FOR SBCS DATA is determined
by the CCSID attribute of the job at the application requester. FOR SBCS DATA
cannot be specified for graphic host-variables.
</dd>
<dt class="bold">FOR MIXED DATA </dt><a id="idx2357" name="idx2357"></a>
<dd>Specifies that the values of the host variable contain both SBCS data
and DBCS data. FOR MIXED DATA is the default if the CCSID attribute of the
job at the application requester is DBCS-capable and the length of the host
variable is greater than 3. The CCSID of FOR DBCS DATA is determined by the
CCSID attribute of the job at the application requester. FOR MIXED DATA cannot
be specified for graphic host-variables.
</dd>
<dt class="bold">CCSID <var class="pv">integer</var></dt>
<dd>Specifies that the values of the host variable contain data of CCSID
integer. If the integer is an SBCS CCSID, the host variable is SBCS data.
If the integer is a mixed data CCSID, the host variable is mixed data. For
character host variables, the CCSID specified must be an SBCS or mixed CCSID.
<p>If the variable has a graphic string data type, the CCSID specified must be
a DBCS, UTF-16, or UCS-2 CCSID. For a list of valid CCSIDs, see <a href="rbafzmstsidvals.htm#sidvals">Appendix E. CCSID values</a>.
Consider specifying CCSID 1200 or 13488 to indicate UTF-16 or UCS-2 data.
If a CCSID is not specified, the CCSID of the graphic string variable will
be the associated DBCS CCSID for the job.</p>
<p>For file reference variables,
the CCSID specifies the CCSID of the path and file name, not the data within
the file.</p>
</dd>
<dt class="bold">DATE </dt>
<dd>Specifies that the values of the host variable contain data that is
a date.
</dd>
<dt class="bold">TIME </dt>
<dd>Specifies that the values of the host variable contain data that is
a time.
</dd>
<dt class="bold">TIMESTAMP </dt>
<dd>Specifies that the values of the host variable contain data that is
a timestamp.
</dd>
</dl>
<a name="wq1442"></a>
<h3 id="wq1442"><a href="rbafzmst02.htm#ToC_1006">Notes</a></h3>
<p><span class="bold">Placement restrictions:</span> The DECLARE VARIABLE statement
can be specified anywhere in an application program that SQL statements are
valid with the following exceptions: </p>
<ul>
<li>If the host language is COBOL or RPG, the DECLARE VARIABLE statement must
occur before an SQL statement that refers to a host variable specified in
the DECLARE VARIABLE statement.</li>
<li>If DATE, TIME, or TIMESTAMP is specified for a NUL-terminated character
string in C, the length of the C declaration will be reduced by one.</li></ul>
<p><span class="bold">Precompiler rules:</span> The following situations result
in an error message during precompile: </p>
<ul>
<li>A reference is made to a variable that does not exist.</li>
<li>A reference is made to a numeric variable.</li>
<li>A reference is made to a variable that has been referred to already.</li>
<li>A reference is made to a variable that is not unique.</li>
<li>The DECLARE VARIABLE statement occurs after an SQL statement where the
SQL statement and the DECLARE VARIABLE statement refer to the same variable.</li>
<li>The FOR BIT DATA, FOR SBCS DATA, or FOR MIXED DATA clause is specified
for a graphic host variable.</li>
<li>A SBCS or mixed CCSID is specified for a graphic host variable.</li>
<li>A DBCS, UTF-16, or UCS-2 CCSID is specified for a character host variable.</li>
<li>DATE, TIME, or TIMESTAMP is specified for a host variable that is not
character.</li>
<li>The length of a host variable used for DATE, TIME, or TIMESTAMP is not
long enough for the minimum date, time, or timestamp value.</li></ul>
<a name="wq1443"></a>
<h3 id="wq1443"><a href="rbafzmst02.htm#ToC_1007">Example</a></h3>
<p>In this example, declare C program variables <span class="italic">fred</span> and <span class="italic">pete</span> as mixed data, and <span class="italic">jean</span> and <span class="italic">dave</span> as SBCS data with CCSID 37.</p>
<p></p>
<a name="xdclvar"></a>
<pre id="xdclvar" class="xmp">void main ()
{
EXEC SQL <span class="bold">BEGIN DECLARE SECTION</span>;
char fred[10];
EXEC SQL <span class="bold">DECLARE</span> :fred <span class="bold">VARIABLE FOR MIXED DATA</span>;
decimal(6,0) mary;
char pete[4];
EXEC SQL <span class="bold">DECLARE</span> :pete <span class="bold">VARIABLE FOR MIXED DATA</span>;
char jean[30];
char dave[9];
EXEC SQL <span class="bold">DECLARE</span> :jean, :dave <span class="bold">VARIABLE CCSID </span>37;
EXEC SQL <span class="bold">END DECLARE SECTION</span>;
EXEC SQL <span class="bold">INCLUDE SQLCA</span>;
...
}
</pre><a id="idx2358" name="idx2358"></a><a id="idx2359" name="idx2359"></a>
<hr /><br />
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmstdclst.htm">Previous Page</a> | <a href="rbafzmstdelst.htm">Next Page</a> | <a href="rbafzmst02.htm#wq1">Contents</a> |
<a href="rbafzmstindex.htm#index">Index</a> ]
<a id="Bot_Of_Page" name="Bot_Of_Page"></a>
</body>
</html>