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

165 lines
12 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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="Sample programs using DB2 UDB for iSeries statements" />
<meta name="abstract" content="This topic contains a sample application showing how to code SQL statements in each of the languages supported by the DB2 UDB for iSeries system." />
<meta name="description" content="This topic contains a sample application showing how to code SQL statements in each of the languages supported by the DB2 UDB for iSeries system." />
<meta name="DC.subject" content="sample programs, statements, using, UDB for, DB2, iSeries, program, sample, statements, C program, ILE RPG program, SQLCA placement" />
<meta name="keywords" content="sample programs, statements, using, UDB for, DB2, iSeries, program, sample, statements, C program, ILE RPG program, SQLCA placement" />
<meta name="DC.Relation" scheme="URI" content="rzajpkickoff.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajpssilec.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajpcobile.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajpstpli.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajpssrpg.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajpssile.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajpssrexx.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajprpsp.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajpc.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajpcob.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajpplone.htm" />
<meta name="DC.Relation" scheme="URI" content="rzajprpg.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="rzajpsamprog" />
<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>Sample programs using DB2 UDB for iSeries statements</title>
</head>
<body id="rzajpsamprog"><a name="rzajpsamprog"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Sample programs using <span class="keyword">DB2 UDB for iSeries</span> statements</h1>
<div><p>This topic contains a sample application showing how to code SQL
statements in each of the languages supported by the <span class="keyword">DB2<sup>®</sup> UDB for iSeries™</span> system.</p>
<div class="section"><p>The sample application gives raises based on commission.</p>
</div>
<div class="section"><p>Each sample program produces the same report, which is shown at
the end of this topic. The first part of the report shows, by project, all
employees working on the project who received a raise. The second part of
the report shows the new salary expense for each project.</p>
</div>
<div class="section"><h4 class="sectiontitle">Notes about the sample programs</h4><p>The following notes
apply to all the sample programs:</p>
<dl><dt class="dlterm"></dt>
<dd>SQL statements can be entered in uppercase or lowercase.</dd>
<dt class="dlterm"><span><span>1</span></span></dt>
<dd>This host language statement retrieves the external definitions for the
SQL table PROJECT. These definitions can be used as host variables or as a
host structure. <div class="note"><span class="notetitle">Notes:</span> <ol><li>In RPG/400<sup>®</sup>,
field names in an externally described structure that are longer than 6 characters
must be renamed.</li>
<li>REXX does not support the retrieval of external definitions.</li>
</ol>
</div>
</dd>
<dt class="dlterm"><span><span>2</span></span></dt>
<dd>The SQL INCLUDE SQLCA statement is used to include the SQLCA for PL/I,
C, and COBOL programs. For RPG programs, the SQL precompiler automatically
places the SQLCA data structure into the source at the end of the Input specification
section. For REXX, the SQLCA fields are maintained in separate variables rather
than in a contiguous data area mapped by the SQLCA.</dd>
<dt class="dlterm"><span><span>3</span></span></dt>
<dd>This SQL WHENEVER statement defines the host language label to which control
is passed if an SQLERROR (SQLCODE &lt; 0) occurs in an SQL statement. This
WHENEVER SQLERROR statement applies to all the following SQL statements until
the next WHENEVER SQLERROR statement is encountered. REXX does not support
the WHENEVER statement. Instead, REXX uses the SIGNAL ON ERROR facility.</dd>
<dt class="dlterm"><span><span>4</span></span></dt>
<dd>This SQL UPDATE statement updates the <em>SALARY</em> column, which contains
the employee salary by the percentage in the host variable PERCENTAGE (PERCNT
for RPG). The updated rows are those that have employee commissions greater
than 2000. For REXX, this is PREPARE and EXECUTE since UPDATE cannot be run
directly if there is a host variable.</dd>
<dt class="dlterm"><span><span>5</span></span></dt>
<dd>This SQL COMMIT statement commits the changes made by the SQL UPDATE statement.
Record locks on all changed rows are released. <div class="note"><span class="notetitle">Note:</span> The program was precompiled
using COMMIT(*CHG). (For REXX, *CHG is the default.)</div>
</dd>
<dt class="dlterm"><span><span>6</span></span></dt>
<dd>This SQL DECLARE CURSOR statement defines cursor C1, which joins two tables,
EMPLOYEE and EMPPROJACT, and returns rows for employees who received a raise
(commission &gt; 2000). Rows are returned in ascending order by project number
and employee number (PROJNO and EMPNO columns). For REXX, this is a PREPARE
and DECLARE CURSOR since the DECLARE CURSOR statement cannot be specified
directly with a statement string if it has host variables.</dd>
<dt class="dlterm"><span><span>7</span></span></dt>
<dd>This SQL OPEN statement opens cursor C1 so that the rows can be fetched.</dd>
<dt class="dlterm"><span><span>8</span></span></dt>
<dd>This SQL WHENEVER statement defines the host language label to which control
is passed when all rows are fetched (SQLCODE = 100). For REXX, the
SQLCODE must be explicitly checked.</dd>
<dt class="dlterm"><span><span>9</span></span></dt>
<dd>This SQL FETCH statement returns all columns for cursor C1 and places
the returned values into the corresponding elements of the host structure.</dd>
<dt class="dlterm"><span><span>10</span></span></dt>
<dd>After all rows are fetched, control is passed to this label. The SQL CLOSE
statement closes cursor C1.</dd>
<dt class="dlterm"><span><span>11</span></span></dt>
<dd>This SQL DECLARE CURSOR statement defines cursor C2, which joins the three
tables, EMPPROJACT, PROJECT, and EMPLOYEE. The results are grouped by columns
PROJNO and PROJNAME. The COUNT function returns the number of rows in each
group. The SUM function calculates the new salary cost for each project. The
ORDER BY 1 clause specifies that rows are retrieved based on the contents
of the final results column (EMPPROJACT.PROJNO). For REXX, this is a PREPARE
and DECLARE CURSOR since the DECLARE CURSOR statement cannot be specified
directly with a statement string if it has host variables.</dd>
<dt class="dlterm"><span><span>12</span></span></dt>
<dd>This SQL FETCH statement returns the results columns for cursor C2 and
places the returned values into the corresponding elements of the host structure
described by the program.</dd>
<dt class="dlterm"><span><span>13</span></span></dt>
<dd>This SQL WHENEVER statement with the CONTINUE option causes processing
to continue to the next statement regardless if an error occurs on the SQL
ROLLBACK statement. Errors are not expected on the SQL ROLLBACK statement;
however, this prevents the program from going into a loop if an error does
occur. SQL statements until the next WHENEVER SQLERROR statement is encountered.
REXX does not support the WHENEVER statement. Instead, REXX uses the SIGNAL
OFF ERROR facility.</dd>
<dt class="dlterm"><span><span>14</span></span></dt>
<dd>This SQL ROLLBACK statement restores the table to its original condition
if an error occurred during the update.</dd>
</dl>
</div>
</div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="rzajpssilec.htm">Example: SQL statements in ILE C and C++ programs</a></strong><br />
This sample program is written in the C programming language.</li>
<li class="ulchildlink"><strong><a href="rzajpcobile.htm">Example: SQL statements in COBOL and ILE COBOL programs</a></strong><br />
This sample program is written in the COBOL programming language.</li>
<li class="ulchildlink"><strong><a href="rzajpstpli.htm">Example: SQL statements in PL/I programs</a></strong><br />
This sample program is written in the PL/I programming language.</li>
<li class="ulchildlink"><strong><a href="rzajpssrpg.htm">Example: SQL statements in RPG/400 programs</a></strong><br />
This sample program is written in the RPG programming language.</li>
<li class="ulchildlink"><strong><a href="rzajpssile.htm">Example: SQL statements in ILE RPG programs</a></strong><br />
This sample program is written in the ILE RPG programming language.</li>
<li class="ulchildlink"><strong><a href="rzajpssrexx.htm">Example: SQL statements in REXX programs</a></strong><br />
This sample program is written in the REXX programming language.</li>
<li class="ulchildlink"><strong><a href="rzajprpsp.htm">Report produced by sample programs that use SQL</a></strong><br />
This report is produced by each of the sample programs.</li>
</ul>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzajpkickoff.htm" title="This topic collection explains how to create database applications in host languages that use DB2 Universal Database for iSeries SQL statements and functions.">Embedded SQL programming</a></div>
</div>
<div class="relconcepts"><strong>Related concepts</strong><br />
<div><a href="rzajpc.htm" title="This topic describes the unique application and coding requirements for embedding SQL statements in a C or C++ program.">Code SQL statements in C and C++ applications</a></div>
<div><a href="rzajpcob.htm" title="This topic describes the unique application and coding requirements for embedding SQL statements in a COBOL program. Requirements for host structures and host variables are defined.">Code SQL statements in COBOL applications</a></div>
<div><a href="rzajpplone.htm" title="This topic describes the unique application and coding requirements for embedding SQL statements in an iSeries PL/I program. Requirements for host structures and host variables are defined.">Code SQL statements in PL/I applications</a></div>
<div><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>