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

103 lines
6.6 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="%OFFSET built-in function" />
<meta name="abstract" content="The offset built-in function (%OFFSET or %OFS) can be used to store or change the offset portion of a CL pointer variable and can only be used within a CL procedure." />
<meta name="description" content="The offset built-in function (%OFFSET or %OFS) can be used to store or change the offset portion of a CL pointer variable and can only be used within a CL procedure." />
<meta name="DC.Relation" scheme="URI" content="contp.htm" />
<meta name="DC.Relation" scheme="URI" content="valuv.htm" />
<meta name="DC.Relation" scheme="URI" content="../clfinder/finder.htm" />
<meta name="DC.Relation" scheme="URI" content="../cl/chgvar.htm" />
<meta name="DC.Relation" scheme="URI" content="rbam6builtinfunc.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="rbam6offset" />
<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>%OFFSET built-in function</title>
</head>
<body id="rbam6offset"><a name="rbam6offset"><!-- --></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">%OFFSET built-in function</h1>
<div><p>The offset built-in function (%OFFSET or %OFS) can be used to store
or change the offset portion of a CL pointer variable and can only be used
within a CL procedure.</p>
<div class="section"><div class="p">In a CHGVAR command, the %OFFSET function can be used two different
ways: <ul><li>You can specify the %OFFSET function for the variable (VAR
parameter) to set the offset portion of a pointer variable.</li>
<li>You can specify the %OFFSET function for the value (VALUE parameter) to
which the variable is to be changed.</li>
</ul>
In an IF command, the %OFFSET function can be specified in the expression
(COND parameter) and is treated like a four-byte unsigned integer value.</div>
<div class="p">The
format of the offset built-in function is:<pre>%OFFSET(variable name)</pre>
or<pre>%OFS(variable name)</pre>
</div>
<p>In
the following example, pointer variable &amp;P1 has no initial value specified
and therefore is initialized to null. The first CHGVAR will store the offset
from the null pointer value in integer variable &amp;I1; the command will
run without an error, and the value of &amp;I1 will probably be zero, though
the offset for a null pointer is not defined. The second CHGVAR command
sets &amp;P1 to the address of local character variable &amp;C1; pointer &amp;P1
now points to byte 1 of variable &amp;C1. The third CHGVAR command will store
the offset portion of &amp;P1 into the integer variable &amp;I2. Note that
the offset is from the start of the storage for all automatic variables for
the current thread and not from the start of automatic storage for the current
program or from the start of variable &amp;C1. The fourth CHGVAR command
takes the integer value stored in &amp;I2, adds one hundred, and stores the
resulting number into the integer variable &amp;I3. The fifth CHGVAR command
changes the offset portion of pointer &amp;P1 using integer variable &amp;I3;
pointer &amp;P1 now points to byte 101 of variable &amp;C1. The sixth CHGVAR
command will calculate the integer expression for the VALUE parameter by storing
the offset portion of pointer &amp;P1 into a temporary integer variable and
subtracting 20, and use this calculated value to reset the offset portion
of pointer &amp;P1; pointer &amp;P1 now points to byte 81 of variable &amp;C1.</p>
<pre>PGM
DCL &amp;C1 *CHAR 30000
DCL &amp;P1 *PTR
DCL &amp;P2 *PTR
DCL &amp;I1 *UINT 4
DCL &amp;I2 *UINT 4
DCL &amp;I3 *UINT 4
CHGVAR &amp;I1 %OFFSET(&amp;P1) /* 1 */
CHGVAR &amp;P1 %ADDRESS(&amp;C1) /* 2 */
CHGVAR &amp;I2 %OFFSET(&amp;P1) /* 3 */
CHGVAR &amp;I3 (%I2+100) /* 4 */
CHGVAR %OFFSET(&amp;P1) &amp;I3 /* 5 */
CHGVAR %OFFSET(&amp;P1) (%OFFSET(&amp;P1)-20) /* 6 */
ENDPGM</pre>
The %OFFSET built-in function cannot be used with a pointer variable
that addresses teraspace storage.</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="contp.htm" title="You can use commands to change the flow of logic within your CL procedure.">Control processing within a CL procedure</a></div>
</div>
<div class="reltasks"><strong>Related tasks</strong><br />
<div><a href="valuv.htm" title="You can change the value of a CL variable using the Change Variable (CHGVAR) command.">Change the value of a variable</a></div>
</div>
<div class="relref"><strong>Related reference</strong><br />
<div><a href="rbam6builtinfunc.htm" title="CL provides several built-in functions.">Built-in functions for CL</a></div>
</div>
<div class="relinfo"><strong>Related information</strong><br />
<div><a href="../clfinder/finder.htm">CL command finder</a></div>
<div><a href="../cl/chgvar.htm">Change Variable (CHGVAR) command</a></div>
</div>
</div>
<img src="./deltaend.gif" alt="End of change" /></body>
</html>