129 lines
7.5 KiB
HTML
129 lines
7.5 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="WHENEVER statement, WHENEVER, SQL statements,
|
||
|
NOT FOUND clause, SQLERROR clause, SQLWARNING clause, CONTINUE clause,
|
||
|
GO TO clause, in WHENEVER statement, host-label, nested programs" />
|
||
|
<title>WHENEVER</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="wvrr"></a>
|
||
|
<h2 id="wvrr"><a href="rbafzmst02.htm#ToC_1398">WHENEVER</a></h2><a id="idx3309" name="idx3309"></a><a id="idx3310" name="idx3310"></a>
|
||
|
<a name="when"></a>
|
||
|
<p id="when">The WHENEVER statement specifies the action to be taken when
|
||
|
a specified exception condition occurs.</p>
|
||
|
<a name="wq1840"></a>
|
||
|
<h3 id="wq1840"><a href="rbafzmst02.htm#ToC_1399">Invocation</a></h3>
|
||
|
<p>This statement can only be embedded in an application program. It is not
|
||
|
an executable statement. It must not be specified in Java™ or
|
||
|
REXX. See the <a href="../rzajp/rzajpkickoff.htm">Embedded SQL Programming</a> book for information
|
||
|
on handling errors in REXX.</p>
|
||
|
<a name="wq1841"></a>
|
||
|
<h3 id="wq1841"><a href="rbafzmst02.htm#ToC_1400">Authorization</a></h3>
|
||
|
<p>None required.</p>
|
||
|
<a name="wq1842"></a>
|
||
|
<h3 id="wq1842"><a href="rbafzmst02.htm#ToC_1401">Syntax</a></h3>
|
||
|
<a href="rbafzmstwvrr.htm#synswhenever"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
|
||
|
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn403.htm"
|
||
|
border="0" /></span><a href="#skipsyn-402"><img src="c.gif" alt="Skip visual syntax diagram"
|
||
|
border="0" /></a>>>-WHENEVER--+-NOT FOUND--+--+-CONTINUE---------------------+--><
|
||
|
+-SQLERROR---+ '-+-GOTO--+--+---+--<span class="italic">host-label</span>-'
|
||
|
'-SQLWARNING-' '-GO TO-' '-:-'
|
||
|
|
||
|
</pre>
|
||
|
<a name="skipsyn-402" id="skipsyn-402"></a>
|
||
|
<a name="synswhenever"></a>
|
||
|
<h3 id="synswhenever"><a href="rbafzmst02.htm#ToC_1402">Description</a></h3>
|
||
|
<p>The NOT FOUND, SQLERROR, or SQLWARNING clause is used to identify the type
|
||
|
of exception condition. </p>
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">NOT FOUND <a id="idx3311" name="idx3311"></a></dt>
|
||
|
<dd>Identifies any condition that results in an SQLSTATE of '02000'
|
||
|
or an SQLCODE of +100.
|
||
|
</dd>
|
||
|
<dt class="bold">SQLERROR <a id="idx3312" name="idx3312"></a></dt>
|
||
|
<dd>Identifies any condition that results in an SQLSTATE value where the
|
||
|
first two characters are not '00', '01', or '02'.
|
||
|
</dd>
|
||
|
<dt class="bold">SQLWARNING </dt><a id="idx3313" name="idx3313"></a>
|
||
|
<dd>Identifies any condition that results in an SQLSTATE value where the
|
||
|
first two characters are '01', or a warning condition (SQLWARN0 is 'W').
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<p>The CONTINUE or GO TO clause are used to specify the next statement to
|
||
|
be executed when the identified type of exception condition exists. </p>
|
||
|
<dl class="parml">
|
||
|
<dt class="bold">CONTINUE </dt><a id="idx3314" name="idx3314"></a>
|
||
|
<dd>Specifies the next sequential instruction of the source program.
|
||
|
</dd>
|
||
|
<dt class="bold">GOTO <span class="base">or</span> GO TO <var class="pv">host-label</var> </dt><a id="idx3315" name="idx3315"></a><a id="idx3316" name="idx3316"></a>
|
||
|
<dd>Specifies the statement identified by <var class="pv">host-label</var>. For host-label,
|
||
|
substitute a single token, optionally preceded by a colon. The form of the
|
||
|
token depends on the host language. In a COBOL program, for example, it can
|
||
|
be a <var class="pv">section-name</var> or an unqualified <var class="pv">paragraph-name</var>.
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<a name="wq1843"></a>
|
||
|
<h3 id="wq1843"><a href="rbafzmst02.htm#ToC_1403">Notes</a></h3>
|
||
|
<p><span class="bold">WHENEVER statement types: </span> There are three types
|
||
|
of WHENEVER statements: </p>
|
||
|
<ul class="simple">
|
||
|
<li>WHENEVER NOT FOUND</li>
|
||
|
<li>WHENEVER SQLERROR</li>
|
||
|
<li>WHENEVER SQLWARNING</li></ul>
|
||
|
<p><span class="bold">WHENEVER statement scope: </span> Every executable SQL statement
|
||
|
in a program is within the scope of one implicit or explicit WHENEVER statement
|
||
|
of each type. The scope of a WHENEVER statement is related to the listing
|
||
|
sequence of the statements in the program, not their execution sequence.</p>
|
||
|
<p>An SQL statement is within the scope of the last WHENEVER statement of
|
||
|
each type that is specified before that SQL statement in the source program.
|
||
|
If a WHENEVER statement of some type is not specified before an SQL statement,
|
||
|
that SQL statement is within the scope of an implicit WHENEVER statement of
|
||
|
that type in which CONTINUE is specified.</p><a id="idx3317" name="idx3317"></a>
|
||
|
<p>SQL does support nested programs in COBOL, C, and RPG. However, SQL does
|
||
|
not honor normal COBOL, C, and RPG scoping rules. That is, the last WHENEVER
|
||
|
statement specified in the program source prior to the nested procedure is
|
||
|
still in effect for that nested program. The label referenced in the WHENEVER
|
||
|
statement must be duplicated within that inner program. Alternatively, the
|
||
|
inner program could specify a new WHENEVER statement.</p>
|
||
|
<p>In FORTRAN, the scope of a WHENEVER statement is limited to SQL statements
|
||
|
within the same subprogram.</p>
|
||
|
<a name="wq1844"></a>
|
||
|
<h3 id="wq1844"><a href="rbafzmst02.htm#ToC_1404">Example</a></h3>
|
||
|
<p>The following statements can be embedded in a COBOL program.</p>
|
||
|
<p><span class="italic">Example 1:</span> Go to the label HANDLER for any statement
|
||
|
that produces an error. </p>
|
||
|
<pre class="xmp"> EXEC SQL <span class="bold">WHENEVER SQLERROR GOTO</span> HANDLER END-EXEC.</pre>
|
||
|
<p><span class="italic">Example 2:</span> Continue processing for any statement
|
||
|
that produces a warning. </p>
|
||
|
<pre class="xmp"> EXEC SQL <span class="bold">WHENEVER SQLWARNING CONTINUE</span> END-EXEC.</pre>
|
||
|
<p><span class="italic">Example 3:</span> Go to the label ENDDATA for any statement
|
||
|
that does not return data when expected to do so. </p>
|
||
|
<pre class="xmp"> EXEC SQL <span class="bold">WHENEVER NOT FOUND GOTO</span> ENDDATA END-EXEC.</pre><a id="idx3318" name="idx3318"></a><a id="idx3319" name="idx3319"></a>
|
||
|
<hr /><br />
|
||
|
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmstvalinto.htm">Previous Page</a> | <a href="rbafzmstsqlcontstmts.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>
|