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

162 lines
8.8 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="Use host structures in ILE RPG applications that use SQL" />
<meta name="abstract" content="The ILE RPG data structure name can be used as a host structure name if subfields exist in the data structure. The use of the data structure name in an SQL statement implies the list of subfield names making up the data structure." />
<meta name="description" content="The ILE RPG data structure name can be used as a host structure name if subfields exist in the data structure. The use of the data structure name in an SQL statement implies the list of subfield names making up the data structure." />
<meta name="DC.subject" content="ILE RPG program, host structure, declaring, ILE RPG, data items, character host variable, ILE RPG, character host variables, host variable, character, subfields" />
<meta name="keywords" content="ILE RPG program, host structure, declaring, ILE RPG, data items, character host variable, ILE RPG, character host variables, host variable, character, subfields" />
<meta name="DC.Relation" scheme="URI" content="rzajprpgi.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="rzajphoststrucirpg" />
<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>Use host structures in ILE RPG applications that use SQL</title>
</head>
<body id="rzajphoststrucirpg"><a name="rzajphoststrucirpg"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Use host structures in ILE RPG applications that use SQL</h1>
<div><p>The ILE RPG data structure name can be used as a <strong>host
structure</strong> name if subfields exist in the data structure. The use of the
data structure name in an SQL statement implies the list of subfield names
making up the data structure.</p>
<div class="section"><p>When a data structure contains one or more unnamed subfields,
the data structure name cannot be used as a host structure in an SQL statement.
The named subfields can be used as host variables.</p>
</div>
<div class="section"><p>In the following example, BIGCHR is an ILE data structure without
subfields. SQL treats any references to BIGCHR as a character string with
a length of 642.</p>
<pre>DBIGCHR DS 642
</pre>
</div>
<div class="section"><p>In the next example, PEMPL is the name of the host structure consisting
of the subfields EMPNO, FIRSTN, MIDINT, LASTNAME, and DEPTNO. A reference
to PEMPL uses the subfields. For example, the first column of CORPDATA.EMPLOYEE
is placed in <em>EMPNO</em>, the second column is placed in <em>FIRSTN</em>, and
so on.</p>
<pre>DPEMPL DS
D EMPNO 01 06A
D FIRSTN 07 18A
D MIDINT 19 19A
D LASTNA 20 34A
D DEPTNO 35 37A
C MOVE '000220' EMPNO
C/EXEC SQL
C+ <strong>SELECT</strong> * <strong>INTO</strong> :PEMPL
C+ <strong>FROM</strong> CORPDATA.EMPLOYEE
C+ <strong>WHERE</strong> EMPNO = :EMPNO
C/END-EXEC
</pre>
</div>
<div class="section"><p>When writing an SQL statement, references to subfields that are
not in a QUALIFIED data structure can be qualified. Use the name of the data
structure, followed by a period and the name of the subfield. For example,
PEMPL.MIDINT is the same as specifying only MIDINT. If the data structure
has the QUALIFIED keyword, then the subfield must be referenced using the
data structure name to qualify the subfield name.</p>
</div>
<div class="section"><p>In this example, we have two data structures, one QUALIFIED and
one not QUALIFIED, that contain the same subfield names:</p>
<pre>Dfststruct DS
D sub1 4B 0
D sub2 9B 0
D sub3 20I 0
D sub4 9B 0
Dsecstruct DS QUALIFIED
D sub1 4A
D sub2 12A
D sub3 20I 0
D myvar 5A
D sub5 20A
D myvar S 10I 0 </pre>
</div>
<div class="section"><p>Referencing <em>secstruct.sub1</em> as a host variable will be a
character variable with a length of 4.</p>
</div>
<div class="section"><p><em>sub2</em> as a host variable will have an SQL data type of small
integer. It picks up its attributes from the data structure that is not QUALIFIED.</p>
</div>
<div class="section"><p>A host variable reference to <em>myvar</em> will use the standalone
declaration to pick up the data type of integer. If you use <em>secstruct.myvar</em>,
the character variable in the QUALIFIED structure will be used. </p>
</div>
<div class="section"><p>You cannot refer to <em>sub5</em> without qualifying it with <em>secstruct</em> because
it is in a QUALIFIED data structure.</p>
</div>
<div class="section"><p>The precompiler will recognize a host structure defined using
the LIKEDS keyword. However, the SQL syntax for a host variable only allows
using a single level of qualification in an SQL statement. This means that
if a data structure DS has a subfield S1 which is defined like a data structure
with a subfield S2, an SQL statement cannot refer to S2 using the fully qualified
host variable name of DS.S1.S2. If you use S1.S2 as the host variable reference,
the precompiler will recognize it as DS.S1.S2. The following additional restrictions
apply: </p>
<ul><li>The top level structure, DS, cannot be an array. </li>
<li>S1.S2 must be unique. That is, there must be no other valid names in the
program ending with S1.S2, such as a structure S1 with a subfield S1.S2, or
a structure DS3 with a subfield DS3.S0.S1.S2. </li>
</ul>
</div>
<div class="section"><h4 class="sectiontitle">Example</h4><pre>D CustomerInfo DS QUALIFIED
D Name 20A
D Address 50A
D ProductInfo DS QUALIFIED
D Number 5A
D Description 20A
D Cost 9P 2
D SalesTransaction...
D DS QUALIFIED
D Buyer LIKEDS(CustomerInfo)
D Seller LIKEDS(CustomerInfo)
D NumProducts 10I 0
D Product LIKEDS(ProductInfo)
D DIM(10)
C/EXEC SQL
C+ SELECT * INTO :CustomerInfo.Name, :Buyer.Name FROM MYTABLE
C/END-EXEC </pre>
</div>
<div class="section"><p><em>CustomerInfo.Name</em> will be recognized as a reference to
the QUALIFIED structure's variable. <em>Buyer.Name</em> will be defined as <em>SalesTransaction.Buyer.Name</em>.</p>
</div>
<div class="section"><p>You cannot use <em>SalesTransaction.Buyer.Name</em> in an SQL statement
because only one level of qualification is allowed in SQL syntax. You cannot
use <em>Product.Cost</em> in an SQL statement because COST is in a dimensioned
array.</p>
</div>
<div class="section"><p>If there is a <em>SalesTransaction2</em> defined like <em>SalesTransaction</em>,
then the subfields that are structures cannot be used in SQL statements. Because
only one level of qualification is supported by SQL, a reference to <em>Buyer.Name</em> is
ambiguous.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzajprpgi.htm" title="This topic describes the unique application and coding requirements for embedding SQL statements in an ILE RPG program. The coding requirements for host variables are defined.">Code SQL statements in ILE RPG applications</a></div>
</div>
</div>
</body>
</html>