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

95 lines
5.1 KiB
HTML
Raw Permalink 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="Use defined variables" />
<meta name="abstract" content="Defined variables make it easy to manage complex data structures in CL by eliminating the need to substring values out of a large variable." />
<meta name="description" content="Defined variables make it easy to manage complex data structures in CL by eliminating the need to substring values out of a large variable." />
<meta name="DC.subject" content="defined variables, defining, variables, variable, description" />
<meta name="keywords" content="defined variables, defining, variables, variable, description" />
<meta name="DC.Relation" scheme="URI" content="workv.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="definedv" />
<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 defined variables</title>
</head>
<body id="definedv"><a name="definedv"><!-- --></a>
<img src="./delta.gif" alt="Start of change" /><!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Use defined variables</h1>
<div><p>Defined variables make it easy to manage complex data structures
in CL by eliminating the need to substring values out of a large variable. </p>
<div class="section"><p>Defined variables can be used to map different parts of the defined
on variable or the same part of a given variable in different ways.</p>
<p>In
the following example, the variables &amp;LIBNAME will always be equal to
the first 10 bytes of &amp;OBJECT. Using the defined variable &amp;LIBNAME
will improves the readability of the code and makes it easier to work with.
The variable &amp;OBJECT provides the storage for the &amp;LIBNAME and &amp;OBJNAME
variables.</p>
<pre>PGM
DCL &amp;OBJECT *CHAR 20
DCL &amp;LIBNAME *CHAR 10 STG(*DEFINED) DEFVAR(&amp;OBJECT)
DCL &amp;OBJNAME *CHAR 10 STG(*DEFINED) DEFVAR(&amp;OBJECT 11)
:
IF COND(%SST(&amp;OBJECT 11 10) *EQ &amp;OBJNAME) +
THEN(...))
:
ENDPGM</pre>
<p>You can also make the same storage with multiple definitions.
In this example, the variables &amp;BINLEN and &amp;CHARLEN both refer to
the same 4 bytes of variable &amp;STRUCT. The program can then use the definition
that best suits its requirements.</p>
<pre>PGM
DCL &amp;STRUCT *CHAR 50
DCL &amp;BINLEN *INT 4 STG(*DEFINED) DEFVAR(&amp;STRUCT)
DCL &amp;CHARLEN *CHAR 4 STG(*DEFINED) DEFVAR(&amp;STRUCT)
:
ENDPGM</pre>
<p>This example shows how a defined variable can be used to change
values in a variable. This example also makes use of the %OFFSET built-in
function and a based variable to navigate the library list. This is not the
optimal way to do message substation but illustrates some of the capabilities
of defined variables.</p>
<pre>PGM
DCL &amp;MESSAGE *CHAR 25 VALUE('LIBRARY NNN IS XXXXXXXXXX')
DCL &amp;SEQUENCE *CHAR 3 STG(*DEFINED) DEFVAR(&amp;MESSAGE 9)
DCL &amp;MSGLIBN *CHAR 10 STG(*DEFINED) DEFVAR(&amp;MESSAGE 16)
DCL &amp;COUNTER *INT 2
DCL &amp;LIBL *CHAR 165
DCL &amp;PTR *PTR ADDRESS(&amp;LIBL)
DCL &amp;LIBLNAME *CHAR 10 STG(*BASED) BASPTR(&amp;PTR)
:
RTVJOBA SYSLIBL(&amp;LIBL)
CHGVAR &amp;COUNTER 0
DOFOR &amp;COUNTER FROM(1) TO(15)
IF (&amp;LIBLNAME *EQ ' ') THEN(LEAVE)
CHGVAR &amp;SEQUENCE &amp;COUNTER
CHGVAR &amp;MSGLIBN &amp;LIBLNAME
SNDPGMMSG MSGID(CPF9898) MSGF(QSYS/QCPFMSG) MSGDTA(&amp;MESSAGE)
CHGVAR %OFS(&amp;PTR) (%OFS(&amp;PTR) + 11)
ENDDO
:
ENDPGM</pre>
</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>
<img src="./deltaend.gif" alt="End of change" /></body>
</html>