ibm-information-center/dist/eclipse/plugins/i5OS.ic.rbam6_5.4.0.1/declv.htm

102 lines
6.1 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 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="Declare a variable" />
<meta name="abstract" content="All variables must be declared (defined) to the CL procedure before they can be used by the procedure." />
<meta name="description" content="All variables must be declared (defined) to the CL procedure before they can be used by the procedure." />
<meta name="DC.subject" content="Declare (DCL) command, declaring, variable, description" />
<meta name="keywords" content="Declare (DCL) command, declaring, variable, description" />
<meta name="DC.Relation" scheme="URI" content="workv.htm" />
<meta name="DC.Relation" scheme="URI" content="../cl/dcl.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="declv" />
<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>Declare a variable</title>
</head>
<body id="declv"><a name="declv"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Declare a variable</h1>
<div><p>All variables must be declared (defined) to the CL procedure before
they can be used by the procedure.</p>
<div class="section"><p>There are two ways of declaring variables:</p>
<ul><li><strong>Declare variable</strong>. Defining it is accomplished using the <span class="cmdname">Declare
CL Variable (DCL)</span> command and consists of defining the attributes
of the variable. These attributes include type, length, and initial value.
<pre>DCL VAR(&amp;AREA) TYPE(*CHAR) LEN(4) VALUE(BOOK)</pre>
</li>
<li><strong>Declare file</strong>. If your CL procedure uses a file, you must specify
the name of the file in the FILE parameter on the Declare File (DCLF) command.
The file contains a description (format) of the records in the file and the
fields in the records. During compilation, the DCLF command implicitly declares
CL variables for the fields and indicators defined in the file. <p>For example,
if the DDS for the file has one record in it with two fields (F1 and F2),
then two variables, &amp;F1 and &amp;F2, are automatically declared in the
program. </p>
<pre>DCLF FILE(MCGANN/GUIDE)</pre>
<p>If the file is a physical file which was created
without DDS, one variable is declared for the entire record. The variable
has the same name as the file, and its length is the same as the record length
of the file.</p>
</li>
</ul>
<p>The declare commands must precede all other commands in the procedure
(except the PGM command), but they can be intermixed in any order.</p>
</div>
<div class="section"><h4 class="sectiontitle">Declare CL Variable (DCL) command</h4><p>In its simplest
form, the Declare CL Variable (DCL) command has the following parameters:</p>
<div class="fignone"><br /><img src="rv2w271.gif" alt="Declare CL Variable (DCL) command has these parameters" /><br /></div>
<p>When you use a DCL command, you must use the following rules:</p>
<ul><li>The CL variable name must begin with an ampersand (&amp;) followed by
as many as 10 characters. The first character following the &amp; must be
alphabetic and the remaining characters alphanumeric. For example, &amp;PART</li>
<li>The CL variable value must be one of the following: <ul><li>A character string as long as 5000 characters.</li>
<li>A packed decimal value totaling up to 15 digits with as many as 9 decimal
positions.</li>
<li>A logical value '0' or '1', where '0' can mean off, false, or no, and
'1' can mean on, true, or yes. A logical variable must be either '0' or '1'.</li>
<li>An integer value of two bytes or four bytes. The value can be negative
if *INT is specified for the TYPE parameter.</li>
<li><img src="./delta.gif" alt="Start of change" />A pointer value which can hold the location of data in storage.<img src="./deltaend.gif" alt="End of change" /></li>
</ul>
</li>
<li>If you do not specify an initial value, the following is assumed: <ul><li>'0' for decimal variables</li>
<li>Blanks for character variables</li>
<li>'0' for logical variables.</li>
<li>'0' for integer variables.</li>
<li><img src="./delta.gif" alt="Start of change" />Null for pointer variables<img src="./deltaend.gif" alt="End of change" /></li>
</ul>
<p>For decimal and character types, if you specify an initial value and
do not specify the LEN parameter, the default length is the same as the length
of the initial value. For type *CHAR, if you do not specify the LEN parameter,
the string can be as long as 5000 characters. For type *INT or *UINT, if you
do not specify the LEN parameter, the default length is 4.</p>
</li>
<li>Declare the parameters as variables in the program DCL statements.</li>
</ul>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="workv.htm" title="CL procedures consist of CL commands, and the commands themselves consist of the command statement, parameters, and parameter values.">Use variables</a></div>
</div>
<div class="relinfo"><strong>Related information</strong><br />
<div><a href="../cl/dcl.htm">Declare CL Variable (DCL) command</a></div>
</div>
</div>
</body>
</html>