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

107 lines
6.2 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<?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="BEGIN DECLARE SECTION statement,
BEGIN DECLARE SECTION, SQL statements, DECLARE statements" />
<title>BEGIN DECLARE SECTION</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="begdcl"></a>
<h2 id="begdcl"><a href="rbafzmst02.htm#ToC_787">BEGIN DECLARE SECTION</a></h2><a id="idx1487" name="idx1487"></a><a id="idx1488" name="idx1488"></a><a id="idx1489" name="idx1489"></a>
<a name="bdecl"></a>
<p id="bdecl"> The BEGIN DECLARE SECTION statement marks the beginning
of an SQL declare section. An SQL declare section contains declarations of
host variables that are eligible to be used as host variables in SQL statements
in a program.</p>
<a name="wq1121"></a>
<h3 id="wq1121"><a href="rbafzmst02.htm#ToC_788">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&trade;,
RPG, or REXX.</p>
<a name="wq1122"></a>
<h3 id="wq1122"><a href="rbafzmst02.htm#ToC_789">Authorization</a></h3>
<p>None required.</p>
<a name="wq1123"></a>
<h3 id="wq1123"><a href="rbafzmst02.htm#ToC_790">Syntax</a></h3>
<a href="rbafzmstbegdcl.htm#synsbegind"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn259.htm"
border="0" /></span><a href="#skipsyn-258"><img src="c.gif" alt="Skip visual syntax diagram"
border="0" /></a>>>-BEGIN DECLARE SECTION--------------------------------------->&lt;
</pre>
<a name="skipsyn-258" id="skipsyn-258"></a>
<a name="synsbegind"></a>
<h3 id="synsbegind"><a href="rbafzmst02.htm#ToC_791">Description</a></h3>
<p>The BEGIN DECLARE SECTION statement is used to indicate the beginning
of an SQL declare section. It can be coded in the application program wherever
variable declarations can appear in accordance with the rules of the host
language. It cannot be coded in the middle of a host structure declaration.
An SQL declare section ends with an END DECLARE SECTION statement, described
in <a href="rbafzmsteds.htm#eds">END DECLARE SECTION</a>.</p>
<p>The BEGIN DECLARE SECTION and the END DECLARE SECTION statements must be
paired and cannot be nested.</p>
<p>SQL statements should not be included within a declare section, with the
exception of the DECLARE VARIABLE and INCLUDE statements.</p>
<p>If SQL declare sections are specified in the program, only the variables
declared within the SQL declare sections can be used as host variables. If
SQL declare sections are not specified in the program, all variables in the
program are eligible for use as host variables.</p>
<p>SQL declare sections should be specified for host languages, other than
RPG and REXX, so that the source program conforms to the IBM&reg; SQL standard
of SQL. SQL declare sections are required for all host variables in C++. The
SQL declare section should appear before the first reference to the variable.
Host variables are declared without the use of these statements in Java and
RPG, and they are not declared at all in REXX.</p>
<p>Variables declared outside an SQL declare section should not have the same
name as variables declared within an SQL declare section.</p>
<p>More than one SQL declare section can be specified in the program.</p>
<a name="wq1124"></a>
<h3 id="wq1124"><a href="rbafzmst02.htm#ToC_792">Examples</a></h3>
<p><span class="italic">Example 1:</span> Define the host variables hv_smint
(SMALLINT), hv_vchar24 (VARCHAR(24)), and hv_double (DOUBLE) in a C
program. </p>
<pre class="xmp"> EXEC SQL <span class="bold">BEGIN DECLARE SECTION</span>;
static short hv_smint;
static struct {
short hv_vchar24_len;
char hv_vchar24_value[24];
} hv_vchar24;
static double hv_double;
EXEC SQL <span class="bold">END DECLARE SECTION</span>;</pre>
<p><span class="italic">Example 2:</span> Define the host variables HV-SMINT (smallint),
HV-VCHAR24 (varchar(24)), and HV-DEC72 (dec(7,2)) in a COBOL program. </p>
<pre class="xmp"> WORKING-STORAGE SECTION.
EXEC SQL <span class="bold">BEGIN DECLARE SECTION</span> END-EXEC.
01 HV-SMINT PIC S9(4) BINARY.
01 HV-VCHAR24.
49 HV-VCHAR24-LENGTH PIC S9(4) BINARY.
49 HV-VCHAR24-VALUE PIC X(24).
01 HV-DEC72 PIC S9(5)V9(2) PACKED-DECIMAL.
EXEC SQL <span class="bold">END DECLARE SECTION</span> END-EXEC.</pre><a id="idx1490" name="idx1490"></a><a id="idx1491" name="idx1491"></a>
<hr /><br />
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmstatabl.htm">Previous Page</a> | <a href="rbafzmstcallsta.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>