438 lines
29 KiB
HTML
438 lines
29 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="description, host variable, application program,
|
|
COBOL, PL/I, RPG, C, REXX, indicator variable, specified by indicator variable,
|
|
null value in SQL, in Java, variable, file reference, LOB locator,
|
|
locator variable, LOB, declaring variable, locator, large object (LOB),
|
|
LOB file reference, file reference variable, host structure, array, indicator,
|
|
host structure arrays" />
|
|
<title>References to variables</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="ch2refvar"></a>
|
|
<h2 id="ch2refvar"><a href="rbafzmst02.htm#ToC_235">References to variables</a></h2>
|
|
<p>A <span class="italic">variable</span> in an SQL statement specifies a value
|
|
that can be changed when the SQL statement is executed. There are several
|
|
types of <span class="italic">variable</span>s used in SQL statements:</p>
|
|
<dl>
|
|
<dt class="bold">host variable</dt>
|
|
<dd>Host variables are defined by statements of a host language. For more
|
|
information about how to refer to host variables see <a href="rbafzmstch2refvar.htm#ch2host">References to host variables</a>.
|
|
</dd>
|
|
<dt class="bold">transition variable</dt>
|
|
<dd>Transition variables are defined in a trigger and refer to either the
|
|
old or new values of columns. For more information about how to refer to transition
|
|
variables see <a href="rbafzmsthctrigger.htm#hctrigger">CREATE TRIGGER</a>.
|
|
</dd>
|
|
<dt class="bold">SQL variable</dt>
|
|
<dd>SQL variables are defined by an SQL compound statement in an SQL function,
|
|
SQL procedure, or trigger. For more information about SQL variables, see <a href="rbafzmstrefsqlv.htm#refsqlv">References to SQL parameters and SQL variables</a>.
|
|
</dd>
|
|
<dt class="bold">SQL parameter</dt>
|
|
<dd>SQL parameters are defined in an CREATE FUNCTION (SQL Scalar),
|
|
CREATE FUNCTION (SQL Table), or CREATE PROCEDURE (SQL) statement. For more
|
|
information about SQL parameters, see <a href="rbafzmstrefsqlv.htm#refsqlv">References to SQL parameters and SQL variables</a>.
|
|
</dd>
|
|
<dt class="bold">parameter marker</dt>
|
|
<dd>Variables cannot be referenced in dynamic SQL statements.
|
|
Parameter markers are defined in an SQL descriptor and used instead. For more
|
|
information about parameter markers, see <a href="rbafzmstpreph2.htm#parmark">Parameter Markers</a>.
|
|
</dd>
|
|
</dl>
|
|
<a name="ch2host"></a>
|
|
<h3 id="ch2host"><a href="rbafzmst02.htm#ToC_236">References to host variables</a></h3><a id="idx591" name="idx591"></a><a id="idx592" name="idx592"></a><a id="idx593" name="idx593"></a><a id="idx594" name="idx594"></a><a id="idx595" name="idx595"></a><a id="idx596" name="idx596"></a>
|
|
<p>A <span class="italic">host variable</span> is a COBOL data item, an RPG field,
|
|
or a PLI, REXX, C++, or C variable that is referenced in an SQL statement.
|
|
Host variables are defined by statements of the host language. For more information
|
|
about how to refer to host structures in C, C++, COBOL, PL/I, and RPG, see <a href="rbafzmstch2refvar.htm#hscpcj">Host structures</a>. For more information about host variables in
|
|
REXX, see the <a href="../rzajp/rzajpkickoff.htm">Embedded SQL Programming</a> book.</p>
|
|
<p>A <var class="pv">host variable</var> in an SQL statement must identify a host variable
|
|
described in the program according to the rules for declaring host variables.</p>
|
|
<p>All host variables used in an SQL statement should be declared in an SQL
|
|
declare section in all host languages other than Java™, REXX, and RPG. Variables do not have
|
|
to be declared in REXX. In Java and RPG, there is no declare section,
|
|
and host variables may be declared throughout the program. No variables may
|
|
be declared outside an SQL declare section with names identical to variables
|
|
declared inside an SQL declare section. An SQL declare section begins with
|
|
BEGIN DECLARE SECTION and ends with END DECLARE SECTION.</p>
|
|
<p>For further information about using host variables, see the <a href="../sqlp/rbafykickoff.htm">Embedded SQL Programming</a> book.</p>
|
|
<p>A variable in the INTO clause of a FETCH, a SELECT INTO, a SET
|
|
variable, a GET DESCRIPTOR, or a VALUES INTO statement identifies a host variable
|
|
to which a value from a result column is assigned. A variable in the GET DIAGNOSTICS
|
|
statement identifies a host variable to which a diagnostic value is assigned.
|
|
A host variable in a CALL or in an EXECUTE statement can be an output argument
|
|
that is assigned a value after execution of the procedure, an input argument
|
|
that provides an input value for the procedure, or both an input and output
|
|
argument. In all other contexts a variable specifies a value to be passed
|
|
to the database manager from the application program.</p>
|
|
<p><span class="bold">Non-Java variable references:</span> The general
|
|
form of a <var class="pv">variable</var> reference in all languages other than Java is:</p>
|
|
<a href="rbafzmstch2refvar.htm#synhl"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq317"></a>
|
|
<div class="fignone" id="wq317">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn14.htm"
|
|
border="0" /></span><a href="#skipsyn-13"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-:<span class="italic">host-identifier</span>--+---------------------------------+-------><
|
|
| .-INDICATOR-. |
|
|
'-+-----------+--:<span class="italic">host-identifier</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-13" id="skipsyn-13"></a></div>
|
|
<a name="synhl"></a>
|
|
<p id="synhl">Each <var class="pv">host-identifier</var> must be declared in the source
|
|
program. The variable designated by the second <var class="pv">host-identifier</var> is
|
|
called an <span class="italic">indicator variable</span> and must have a data
|
|
type of small integer.</p>
|
|
<p>The purposes of the indicator variable are to: </p>
|
|
<ul>
|
|
<li>Specify the null value. A negative value of the indicator variable specifies
|
|
the null value.</li>
|
|
<li>Indicate that one of the following numeric conversion errors:
|
|
<ul>
|
|
<li>Numeric conversion error (underflow or overflow)</li>
|
|
<li>Arithmetic expression error (division by 0)</li>
|
|
<li>A numeric value that is not valid</li></ul></li>
|
|
<li>Indicate one of the following string errors:
|
|
<ul>
|
|
<li>Characters could not be converted</li>
|
|
<li>Mixed data not properly formed</li></ul></li>
|
|
<li>Indicate one of the following datetime errors:
|
|
<ul>
|
|
<li>Date or timestamp conversion error (a date or timestamp that is not within
|
|
the valid range of the dates for the specified format)</li>
|
|
<li>String representation of the datetime value is not valid</li></ul></li>
|
|
<li>Indicate one of the following miscellaneous errors:
|
|
<ul>
|
|
<li>Argument of SUBSTR scalar function is out of range</li>
|
|
<li>Argument of a decryption function contains a data type that is not valid.</li></ul></li>
|
|
<li>Record the original length of a string if the string is truncated on assignment
|
|
to a host variable. If the string is truncated and there is no indicator variable,
|
|
no error condition results.</li>
|
|
<li>Record the seconds portion of a time if the time is truncated on assignment
|
|
to a host variable. If the time is truncated and there is no indicator variable,
|
|
no error condition results.</li></ul><a id="idx597" name="idx597"></a><a id="idx598" name="idx598"></a>
|
|
<p>For example, if :V1:V2 is used to specify an insert or update value, and
|
|
if V2 is negative, the value specified is the null value. If V2 is not negative
|
|
the value specified is the value of V1.</p>
|
|
<p>Similarly, if :V1:V2 is specified in a CALL, FETCH, SELECT INTO, or VALUES
|
|
INTO statement and the value returned is null, V1 is undefined, and V2 is
|
|
set to a negative value. The negative value is: </p>
|
|
<ul>
|
|
<li>-1 if the value selected was the null value, or</li>
|
|
<li>-2 if the null value was returned due to data mapping errors in the select
|
|
list of an outer subselect. <sup class="fn"><a id="wq318" name="wq318" href="rbafzmstch2refvar.htm#wq319">32</a></sup></li></ul><p class="indatacontent"> If the value returned is not null, that value is assigned to V1 and
|
|
V2 is set to zero (unless the assignment to V1 requires string truncation,
|
|
in which case, V2 is set to the original length of the string). If an assignment
|
|
requires truncation of the seconds part of time, V2 is set to the number of
|
|
seconds.</p>
|
|
<p>If the second <span class="italic">host-identifier</span> is omitted, the <var class="pv">host variable</var> does not have an indicator variable. The value specified
|
|
by the <var class="pv">host variable</var> :V1 is always the value of V1, and null values
|
|
cannot be assigned to the variable. Thus, this form should not be used unless
|
|
the corresponding result column cannot contain null values. If this form is
|
|
used and the column contains nulls, the database manager will return an error at run-time
|
|
(SQLSTATE 23502).</p>
|
|
<p>An SQL statement that references host variables in C, C++, ILE
|
|
RPG, and PL/I, must be within the scope of the declaration of those host variables.
|
|
For host variables referenced in the SELECT statement of a cursor, that rule
|
|
applies to the OPEN statement rather than to the DECLARE CURSOR statement.</p>
|
|
<p>The CCSID of a string host variable is either: </p>
|
|
<ul>
|
|
<li>The CCSID specified in the DECLARE VARIABLE statement, or</li>
|
|
<li>If a DECLARE VARIABLE with a CCSID clause is not specified for the host
|
|
variable, the default CCSID of the application requester at the time the SQL
|
|
statement that contains the host variable is executed unless the CCSID is
|
|
for a foreign encoding scheme (such as ASCII). In this case, the host variable
|
|
is converted to the default CCSID of the current server.</li></ul>
|
|
<p><span class="bold">Java variable references:</span> The general
|
|
form of a host variable reference in Java is: <a id="idx599" name="idx599"></a>
|
|
</p>
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn15.htm"
|
|
border="0" /></span><a href="#skipsyn-14"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-:--+-------+--+-<span class="italic">Java-identifier</span>-------+---------------------><
|
|
+-IN----+ '-(--<span class="italic">Java-expression</span>--)-'
|
|
+-OUT---+
|
|
'-INOUT-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-14" id="skipsyn-14"></a>
|
|
<p>In Java, indicator variables are not used. Instead, instances of a Java class
|
|
can be set to a null value. Variables defined as Java primitive types cannot be set to a
|
|
null value.</p>
|
|
<p>If IN, OUT, or INOUT is not specified, the default depends on the context
|
|
in which the variable is used. If the Java variable is used in an INTO clause,
|
|
OUT is the default. Otherwise, IN is the default. For more information on Java variables, see <a href="../rzaha/whatitis.htm">IBM® Developer Kit for Java</a>.</p>
|
|
<a name="wq320"></a>
|
|
<h4 id="wq320">Example</h4>
|
|
<p>Using the PROJECT table, set the host variable PNAME (VARCHAR(26)) to the
|
|
project name (PROJNAME), the host variable STAFF (DECIMAL(5,2)) to the mean
|
|
staffing level (PRSTAFF), and the host variable MAJPROJ (CHAR(6)) to the major
|
|
project (MAJPROJ) for project (PROJNO) 'IF1000'. Columns PRSTAFF and
|
|
MAJPROJ may contain null values, so provide indicator variables STAFF_IND
|
|
(SMALLINT) and MAJPROJ_IND (SMALLINT). </p>
|
|
<pre class="xmp"> <span class="bold">SELECT</span> PROJNAME, PRSTAFF, MAJPROJ
|
|
<span class="bold">INTO</span> :PNAME, :STAFF :STAFF_IND, :MAJPROJ :MAJPROJ_IND
|
|
<span class="bold">FROM</span> PROJECT
|
|
<span class="bold">WHERE</span> PROJNO <span class="bold">=</span> 'IF1000'</pre>
|
|
<a name="wq321"></a>
|
|
<h3 id="wq321"><a href="rbafzmst02.htm#ToC_238">Variables in dynamic SQL</a></h3>
|
|
<p>In dynamic SQL statements, parameter markers are used instead of variables.
|
|
A parameter marker is a question mark (?) that represents a position in a
|
|
dynamic SQL statement where the application will provide a value; that is,
|
|
where a variable would be found if the statement string were a static SQL
|
|
statement. The following examples shows a static SQL that uses host variables
|
|
and a dynamic statement that uses parameter markers: </p>
|
|
<pre class="xmp"> <span class="bold">INSERT INTO</span> DEPT
|
|
<span class="bold">VALUES(</span> :HV_DEPTNO, :HV_DEPTNAME, :HV_MGRNO:IND_MGRNO, :HV_ADMRDEPT<span class="bold">)</span>
|
|
|
|
<span class="bold">INSERT INTO</span> DEPT
|
|
<span class="bold">VALUES(</span> ?, ?, ?, ? <span class="bold">)</span> </pre>
|
|
<p>For more information about parameter markers, see <a href="rbafzmstpreph2.htm#parmark">Parameter Markers</a>.</p>
|
|
<a name="wq322"></a>
|
|
<h3 id="wq322"><a href="rbafzmst02.htm#ToC_239">References to LOB variables</a></h3>
|
|
<p>Regular LOB variables, LOB locator variables (see <a href="rbafzmstch2refvar.htm#rlobloc">References to LOB locator variables</a>)
|
|
and LOB file reference variables (see <a href="rbafzmstch2refvar.htm#rlobref">References to LOB file reference variables</a>), can be defined
|
|
in the following host languages:</p>
|
|
<ul>
|
|
<li>C</li>
|
|
<li>C++</li>
|
|
<li>ILE RPG</li>
|
|
<li>ILE COBOL</li>
|
|
<li>PL/I</li></ul><p class="indatacontent"> Where LOBs are allowed, the term <span class="italic">variable</span> in a syntax diagram can refer to a regular variable, a locator variable,
|
|
or a file reference variable. Since these variables are not native data types
|
|
in host programming languages, SQL extensions are used and the precompilers
|
|
generate the host language constructs necessary to represent each variable.</p>
|
|
<p>When it is possible to define a variable that is large enough to hold an
|
|
entire LOB value and the performance benefit of delaying the transfer of data
|
|
from the server is not required, a LOB locator is not needed. However, it
|
|
is often not acceptable to store an entire LOB value in temporary storage
|
|
due to host language restrictions, storage restrictions, or performance requirements.
|
|
When storing a entire LOB value at one time is not acceptable, a LOB value
|
|
can be referred to by a LOB locator and portions of the LOB value can be accessed.</p>
|
|
<a name="rlobloc"></a>
|
|
<h3 id="rlobloc"><a href="rbafzmst02.htm#ToC_240">References to LOB locator variables</a></h3><a id="idx600" name="idx600"></a><a id="idx601" name="idx601"></a><a id="idx602" name="idx602"></a><a id="idx603" name="idx603"></a><a id="idx604" name="idx604"></a><a id="idx605" name="idx605"></a>
|
|
<p>A LOB <span class="italic">locator variable</span> is a variable that contains
|
|
the locator representing a LOB value on the application server, which can be defined
|
|
in the following host languages:</p>
|
|
<ul>
|
|
<li>C</li>
|
|
<li>C++</li>
|
|
<li>ILE RPG</li>
|
|
<li>ILE COBOL</li>
|
|
<li>PL/I</li></ul><p class="indatacontent">See <a href="rbafzmstch2data.htm#mlobloc">Manipulating large objects with locators</a> for information on how locators can be used
|
|
to manipulate LOB values.</p>
|
|
<p>A locator variable in an SQL statement must identify a LOB locator variable
|
|
described in the program according to the rules for declaring locator variables.
|
|
This is always indirectly through an SQL statement. For example, in C: </p>
|
|
<pre class="xmp"> static volatile <span class="bold">SQL TYPE IS CLOB_LOCATOR</span> *loc1;</pre>
|
|
<p>The term <span class="italic">locator-variable</span>, as used in the syntax
|
|
diagrams, shows a reference to a LOB locator variable. The meta-variable <span class="italic">locator-variable</span> can be expanded to include a <span class="italic">host-identifier</span> the same as that for <span class="italic">host-variable</span>.</p>
|
|
<p>Like all other variables, a LOB locator variable can have an
|
|
associated indicator variable. Indicator variables for LOB locator variables
|
|
behave in the same way as indicator variables for other data types. When a
|
|
null value is returned from the database, the indicator variable is set and
|
|
the variable is unchanged. When the indicator variable associated with a LOB
|
|
locator is null, the value of the referenced LOB is null. This means that
|
|
a locator can never point to a null value.</p>
|
|
<p>If a locator variable does not currently represent any value, an error
|
|
occurs when the locator variable is referenced.</p>
|
|
<p>At transaction commit or any transaction termination, all LOB locators
|
|
that were acquired by the transaction are released.</p>
|
|
<p>It is the application programmer's responsibility to guarantee that any
|
|
LOB locator is only used in SQL statements that are executed at the same application server that
|
|
originally generated the LOB locator. For example, assume that a LOB locator
|
|
is returned from one application server and assigned to a LOB locator variable. If
|
|
that LOB locator variable is subsequently used in an SQL statement that is
|
|
executed at a different application server, unpredictable results will occur.</p>
|
|
<a name="rlobref"></a>
|
|
<h3 id="rlobref"><a href="rbafzmst02.htm#ToC_241">References to LOB file reference variables</a></h3><a id="idx606" name="idx606"></a><a id="idx607" name="idx607"></a><a id="idx608" name="idx608"></a><a id="idx609" name="idx609"></a><a id="idx610" name="idx610"></a>
|
|
<p>A LOB <span class="italic">file reference variable</span> is used for direct
|
|
file input and output for a LOB, which can be defined in the following host
|
|
languages:</p>
|
|
<ul>
|
|
<li>C</li>
|
|
<li>C++</li>
|
|
<li>ILE RPG</li>
|
|
<li>ILE COBOL</li>
|
|
<li>PL/I</li></ul><p class="indatacontent">Since these are not native data types, SQL extensions are used and the
|
|
precompilers generate the host language constructs necessary to represent
|
|
each variable.</p>
|
|
<p>A file reference variable represents (rather than contains) the file, just
|
|
as a LOB locator represents, rather than contains, the LOB data. Database
|
|
queries, updates, and inserts may use file reference variables to store or
|
|
to retrieve single column values. The file referenced must exist at the application
|
|
requester.</p>
|
|
<p>Like all other variables, a file reference variable can have
|
|
an associated indicator variable. Indicator variables for file reference variables
|
|
behave in the same way as indicator variables for other data types. When a
|
|
null value is returned from the database, the indicator variable is set and
|
|
the variable is unchanged. When the indicator variable associated with a file
|
|
reference variable is null, the value of the referenced LOB is null. This
|
|
means that a file reference variable can never point to a null value.</p>
|
|
<p>The length attribute of a file reference variable is assumed to be the
|
|
maximum length of a LOB.</p>
|
|
<p>File reference variables are currently supported in the root (/), QOpenSys,
|
|
and UDFS file systems. When a file is created, it is given the CCSID of the
|
|
data that is being written to the file. Currently, mixed CCSIDs are not supported.
|
|
To use a file created with a file reference variable, the file should be opened
|
|
in binary mode.</p>
|
|
<p>For more information about file reference variables, see the <a href="../sqlp/rbafykickoff.htm">SQL Programming</a> book.</p>
|
|
<a name="hscpcj"></a>
|
|
<h3 id="hscpcj"><a href="rbafzmst02.htm#ToC_242">Host structures</a></h3><a id="idx611" name="idx611"></a><a id="idx612" name="idx612"></a><a id="idx613" name="idx613"></a><a id="idx614" name="idx614"></a><a id="idx615" name="idx615"></a>
|
|
<p>A host structure is a COBOL group, PL/I, C, or C++ structure, or RPG data
|
|
structure that is referenced in an SQL statement. Host structures are defined
|
|
by statements of the host language, as explained in the <a href="../rzajp/rzajpkickoff.htm">Embedded SQL Programming</a> book. As used here, the term host structure
|
|
does not include an SQLCA or SQLDA.</p>
|
|
<p>The form of a host structure reference is identical to the form of a host
|
|
variable reference. The reference :S1:S2 is a host structure reference if
|
|
S1 names a host structure. If S1 designates a host structure, S2 must be either
|
|
a small integer variable, or an array of small integer variables. S1 is the
|
|
host structure and S2 is its indicator array.</p>
|
|
<p>A host structure can be referenced in any context where a list of host
|
|
variables can be referenced. A host structure reference is equivalent to a
|
|
reference to each of the host variables contained within the structure in
|
|
the order which they are defined in the host language structure declaration.
|
|
The <span class="italic">n</span>th variable of the indicator array is the indicator
|
|
variable for the <span class="italic">n</span>th variable of the host structure.</p>
|
|
<p>In C, for example, if V1, V2, and V3 are declared as variables within the
|
|
structure S1, the statement: </p>
|
|
<a name="ref2x6"></a>
|
|
<pre id="ref2x6" class="xmp"> EXEC SQL <span class="bold">FETCH</span> CURSOR1 <span class="bold">INTO</span> :S1;</pre>
|
|
<p>is equivalent to: </p>
|
|
<a name="ref2x7"></a>
|
|
<pre id="ref2x7" class="xmp"> EXEC SQL <span class="bold">FETCH</span> CURSOR1 <span class="bold">INTO</span> :V1, :V2, :V3;</pre>
|
|
<p>If the host structure has <span class="italic">m</span> more variables than
|
|
the indicator array, the last <span class="italic">m</span> variables of the host
|
|
structure do not have indicator variables. If the host structure has <span class="italic">m</span> fewer variables than the indicator array, the last <span class="italic">m</span> variables of the indicator array are ignored. These rules also apply
|
|
if a reference to a host structure includes an indicator variable or if a
|
|
reference to a host variable includes an indicator array. If an indicator
|
|
array or indicator variable is not specified, no variable of the host structure
|
|
has an indicator variable.</p><a id="idx616" name="idx616"></a><a id="idx617" name="idx617"></a>
|
|
<p>In addition to structure references, individual host variables in the host
|
|
structure or indicator variables in the indicator array can be referenced
|
|
by qualified names. The qualified form is a host identifier followed by a
|
|
period and another host identifier. The first host identifier must name a
|
|
host structure, and the second host identifier must name a host variable within
|
|
that host structure.</p>
|
|
<p>The general form of a host variable or host structure reference is:</p>
|
|
<a href="rbafzmstch2refvar.htm#synhlcobol"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq323"></a>
|
|
<div class="fignone" id="wq323">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn16.htm"
|
|
border="0" /></span><a href="#skipsyn-15"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-:--+------------------+--<span class="italic">host-identifier</span>--------------------->
|
|
'-<span class="italic">host-identifier.</span>-'
|
|
|
|
>--+---------------------------------------------------------+-><
|
|
| .-INDICATOR-. |
|
|
'-+-----------+--:--+------------------+--<span class="italic">host-identifier</span>-'
|
|
'-<span class="italic">host-identifier.</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-15" id="skipsyn-15"></a></div>
|
|
<a name="synhlcobol"></a>
|
|
<p id="synhlcobol">A <span class="italic">host-variable</span> in an expression
|
|
must identify a host variable (not a structure) described in the program according
|
|
to the rules for declaring host variables.</p>
|
|
<p>The following C example shows a references to host structure, host indicator
|
|
array, and a host variable: </p>
|
|
<pre class="xmp"> struct { char empno[7];
|
|
struct { short int firstname_len;
|
|
char firstname_text[12];
|
|
} firstname;
|
|
char midint,
|
|
struct { short int lastname_len;
|
|
char lastname_text[15];
|
|
} lastname;
|
|
char workdept[4];
|
|
} pemp1;
|
|
short ind[14];
|
|
short eind
|
|
struct { short ind1;
|
|
short ind2;
|
|
} indstr;
|
|
|
|
.....
|
|
strcpy(pemp1.empno,"000220");
|
|
.....
|
|
EXEC SQL
|
|
<span class="bold">SELECT</span> *
|
|
<span class="bold">INTO</span> :pemp1:ind
|
|
<span class="bold">FROM</span> corpdata.employee
|
|
<span class="bold">WHERE</span> empno=:pemp1.empno;</pre>
|
|
<p>In the example above, the following references to host variables and host
|
|
structures are valid: </p>
|
|
<pre class="xmp"> :pemp1 :pemp1.empno :pemp1.empno:eind :pemp1.empno:indstr.ind1</pre>
|
|
<a name="array"></a>
|
|
<h3 id="array"><a href="rbafzmst02.htm#ToC_243">Host structure arrays</a></h3><a id="idx618" name="idx618"></a><a id="idx619" name="idx619"></a><a id="idx620" name="idx620"></a><a id="idx621" name="idx621"></a><a id="idx622" name="idx622"></a>
|
|
<p>In PL/I, C++, and C, a host structure array is a structure name having
|
|
a dimension attribute. In COBOL, it is a one-dimensional table. In RPG, it
|
|
is an occurrence data structure. In ILE RPG, it can also be a data structure
|
|
with the keyword DIM. A host structure array can only be referenced in the
|
|
FETCH statement when using a multiple-row fetch, or in an INSERT statement
|
|
when using a multiple-row insert. Host structure arrays are defined by statements
|
|
of the host language, as explained in the <a href="../rzajp/rzajpkickoff.htm">Embedded SQL
|
|
Programming</a> book.</p>
|
|
<p>The form of a host structure array is identical to the form of a host variable
|
|
reference. The reference :S1:S2 is a reference to host structure array if
|
|
S1 names a host structure array. If S1 designates a host structure, S2 must
|
|
be either a small integer host variable, an array of small integer host variables,
|
|
or a two dimensional array of small integer host variables. In the following
|
|
example, S1 is the host structure array and S2 is its indicator array. </p>
|
|
<pre class="xmp"> EXEC SQL <span class="bold">FETCH</span> CURSOR1 <span class="bold">FOR</span> 5 <span class="bold">ROWS
|
|
INTO</span> :S1:S2;</pre>
|
|
<p>The dimension of the host structure and the indicator array must be equal.</p>
|
|
<p>If the host structure has <span class="italic">m</span> more variables than
|
|
the indicator array, the last <span class="italic">m</span> variables of the host
|
|
structure do not have indicator variables. If the host structure has <span class="italic">m</span> fewer variables than the indicator array, the last <span class="italic">m</span> variables of the indicator array are ignored. If an indicator array
|
|
or variable is not specified, no variable of the host structure array has
|
|
an indicator variable.</p>
|
|
<p>The following diagram specifies the syntax of references to an array of
|
|
host structures:</p>
|
|
<a href="rbafzmstch2refvar.htm#synhlarray"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
|
<a name="wq324"></a>
|
|
<div class="fignone" id="wq324">
|
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn17.htm"
|
|
border="0" /></span><a href="#skipsyn-16"><img src="c.gif" alt="Skip visual syntax diagram"
|
|
border="0" /></a>>>-:--<span class="italic">host-identifier</span>--+-----------------------------------+---><
|
|
| .-INDICATOR-. |
|
|
'-+-----------+--:--<span class="italic">host-identifier</span>-'
|
|
|
|
</pre>
|
|
<a name="skipsyn-16" id="skipsyn-16"></a></div>
|
|
<a name="synhlarray"></a>
|
|
<p id="synhlarray">Arrays of host structures are not supported in REXX.</p>
|
|
<hr /><div class="fnnum"><a id="wq319" name="wq319" href="rbafzmstch2refvar.htm#wq318">32</a>.</div>
|
|
<div class="fntext">It should be noted that although the null
|
|
value returned for data mapping errors can be returned on certain scalar functions
|
|
and for arithmetic expressions, the result column is not considered null capable
|
|
unless an argument of the arithmetic expression or scalar function is null
|
|
capable.</div>
|
|
<br />
|
|
<hr /><br />
|
|
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmstch2col.htm">Previous Page</a> | <a href="rbafzmstch2function.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>
|