95 lines
5.1 KiB
HTML
95 lines
5.1 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 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 &LIBNAME will always be equal to
|
||
|
the first 10 bytes of &OBJECT. Using the defined variable &LIBNAME
|
||
|
will improves the readability of the code and makes it easier to work with.
|
||
|
The variable &OBJECT provides the storage for the &LIBNAME and &OBJNAME
|
||
|
variables.</p>
|
||
|
<pre>PGM
|
||
|
DCL &OBJECT *CHAR 20
|
||
|
DCL &LIBNAME *CHAR 10 STG(*DEFINED) DEFVAR(&OBJECT)
|
||
|
DCL &OBJNAME *CHAR 10 STG(*DEFINED) DEFVAR(&OBJECT 11)
|
||
|
:
|
||
|
IF COND(%SST(&OBJECT 11 10) *EQ &OBJNAME) +
|
||
|
THEN(...))
|
||
|
:
|
||
|
ENDPGM</pre>
|
||
|
<p>You can also make the same storage with multiple definitions.
|
||
|
In this example, the variables &BINLEN and &CHARLEN both refer to
|
||
|
the same 4 bytes of variable &STRUCT. The program can then use the definition
|
||
|
that best suits its requirements.</p>
|
||
|
<pre>PGM
|
||
|
DCL &STRUCT *CHAR 50
|
||
|
DCL &BINLEN *INT 4 STG(*DEFINED) DEFVAR(&STRUCT)
|
||
|
DCL &CHARLEN *CHAR 4 STG(*DEFINED) DEFVAR(&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 &MESSAGE *CHAR 25 VALUE('LIBRARY NNN IS XXXXXXXXXX')
|
||
|
DCL &SEQUENCE *CHAR 3 STG(*DEFINED) DEFVAR(&MESSAGE 9)
|
||
|
DCL &MSGLIBN *CHAR 10 STG(*DEFINED) DEFVAR(&MESSAGE 16)
|
||
|
DCL &COUNTER *INT 2
|
||
|
DCL &LIBL *CHAR 165
|
||
|
DCL &PTR *PTR ADDRESS(&LIBL)
|
||
|
DCL &LIBLNAME *CHAR 10 STG(*BASED) BASPTR(&PTR)
|
||
|
:
|
||
|
RTVJOBA SYSLIBL(&LIBL)
|
||
|
CHGVAR &COUNTER 0
|
||
|
DOFOR &COUNTER FROM(1) TO(15)
|
||
|
IF (&LIBLNAME *EQ ' ') THEN(LEAVE)
|
||
|
CHGVAR &SEQUENCE &COUNTER
|
||
|
CHGVAR &MSGLIBN &LIBLNAME
|
||
|
SNDPGMMSG MSGID(CPF9898) MSGF(QSYS/QCPFMSG) MSGDTA(&MESSAGE)
|
||
|
CHGVAR %OFS(&PTR) (%OFS(&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>
|