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

169 lines
9.8 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="%BINARY built-in function" />
<meta name="abstract" content="The binary built-in function (%BINARY or %BIN) interprets the contents of a specified CL character variable as a signed binary integer." />
<meta name="description" content="The binary built-in function (%BINARY or %BIN) interprets the contents of a specified CL character variable as a signed binary integer." />
<meta name="DC.subject" content="%BINARY (binary) built-in function, description, %BIN (binary) function, binary function, example, BIN function" />
<meta name="keywords" content="%BINARY (binary) built-in function, description, %BIN (binary) function, binary function, example, BIN function" />
<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/if.htm" />
<meta name="DC.Relation" scheme="URI" content="../cl/chgvar.htm" />
<meta name="DC.Relation" scheme="URI" content="../cl/callprc.htm" />
<meta name="DC.Relation" scheme="URI" content="../cl/sndpgmmsg.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="binar" />
<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>%BINARY built-in function</title>
</head>
<body id="binar"><a name="binar"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">%BINARY built-in function</h1>
<div><p>The binary built-in function (%BINARY or %BIN) interprets the contents
of a specified CL character variable as a signed binary integer. </p>
<div class="section"><p>The starting position begins at the position specified and continues
for a length of 2 or 4 characters.</p>
<p>The syntax of the binary built-in
function is shown in the following example: </p>
<pre>%BINARY(character-variable-name starting-position length)</pre>
<p>You can also code it like this example:</p>
<pre>%BIN(character-variable-name starting-position length)</pre>
<p>The starting position and length are optional. However, if
the starting position and length are <em>not specified</em>, a starting position
of 1 and length of the character variable that is specified are used. In that
case, you must declare the length of the character variable as either 2 or
4.</p>
<p>If the starting position <em>is specified</em>, you must also specify
a constant length of 2 or 4. The starting position must be a positive number
equal to or greater than 1. If the sum of the starting position and the length
is greater than the length of the character variable, an error occurs. (A
CL decimal or integer variable may also be used for the starting position.)</p>
<p>You
can use the binary built-in function with both the <span class="cmdname">If (IF)</span> and <span class="cmdname">Change
Variable (CHGVAR)</span> commands. It can be used by itself or as part
of an arithmetic or logical expression. You can also use the binary built-in
function on any command parameter that is defined as numeric (TYPE of *DEC,
*INT2, *INT4, *UINT2, or *UINT4) with EXPR(*YES).</p>
<p>When the binary built-in
function is used with the condition (COND) parameter on the IF command or
with the VALUE parameter on the <span class="cmdname">Change Variable (CHGVAR)</span> command,
the contents of the character variable is interpreted as a binary-to-decimal
conversion.</p>
<p>When the binary built-in function is used with the VAR parameter
on the <span class="cmdname">Change Variable (CHGVAR)</span> command, the decimal value
in the VALUE parameter is converted to a 2-byte or 4-byte signed binary integer
and the result stored in the character variable at the starting position specified.
Decimal fractions are truncated.</p>
<p>The system uses the binary built-in
function on the RTNVAL parameter of the <span class="cmdname">Call Bound Procedure (CALLPRC)</span> command
to indicate that the calling procedure expects the called procedure to return
a signed binary integer.</p>
<p>A 2-byte character variable can hold signed
binary integer values from -32 768 through 32 767. A 4-byte character variable
can hold signed binary integer values from -2 147 483 648 through 2 147 483
647.</p>
<p>The following are examples of the binary built-in function:</p>
<ul><li> <pre>DCL VAR(&amp;B2) TYPE(*CHAR) LEN(2) VALUE(X'001C')
DCL VAR(&amp;N) TYPE(*DEC) LEN(3 0)
CHGVAR &amp;N %BINARY(&amp;B2)</pre>
<p>The contents of variable &amp;B2 is treated as a 2-byte signed
binary integer and converted to its decimal equivalent of 28. It is then
assigned to the decimal variable &amp;N</p>
</li>
<li> <pre>DCL VAR(&amp;N) TYPE(*DEC) LEN(5 0) VALUE(107)
DCL VAR(&amp;B4) TYPE(*CHAR) LEN(4)
CHGVAR %BIN(&amp;B4) &amp;N</pre>
<p>The value of the decimal variable &amp;N is converted to a
4-byte signed binary number and is placed in character variable &amp;B4 Variable &amp;B4
will have the value of <span>X'0000006B'</span>.</p>
</li>
<li> <pre>DCL VAR(&amp;P) TYPE(*CHAR) LEN(100)
DCL VAR(&amp;L) TYPE(*DEC) LEN(5 0)
CHGVAR &amp;L VALUE(%BIN(&amp;P 1 2) * 5)</pre>
<p>The first two characters of variable &amp;P is treated as a
signed binary integer, converted to its decimal equivalent, and multiplied
by 5. The product is assigned to the decimal variable &amp;L.</p>
</li>
<li> <pre>DCL VAR(&amp;X) TYPE(*CHAR) LEN(50)
CHGVAR %BINARY(&amp;X 15 2) VALUE(122.56)</pre>
<p>The number 122.56 is truncated to the whole number 122 and
is then converted to a 2-byte signed binary integer and is placed at positions
15 and 16 of the character variable &amp;X. Positions 15 and 16 of variable &amp;X
will contain the hexadecimal equivalent of <span>X'007A'</span>.</p>
</li>
<li> <pre>DCL VAR(&amp;B4) TYPE(*CHAR) LEN(4)
CHGVAR %BIN(&amp;B4) VALUE(-57)</pre>
<p>The value -57 is converted to a 4-byte signed binary integer
and assigned to the character variable &amp;B4. The variable &amp;B4 will
then contain the value <span>X'FFFFFFC7'</span>.</p>
</li>
<li> <pre>DCL VAR(&amp;B2) TYPE(*CHAR) LEN(2) VALUE(X'FF1B')
DCL VAR(&amp;C5) TYPE(*CHAR) LEN(5)
CHGVAR &amp;C5 %BINARY(&amp;B2)</pre>
<p>The contents of variable &amp;B2 is treated as a 2-byte signed
binary integer and converted to its decimal equivalent of -229. The number
is converted to character form and stored in the variable character &amp;C5.
The character variable &amp;C5 will then contain the value '-0229'.</p>
</li>
<li> <pre>DCL VAR(&amp;C5) TYPE(*CHAR) LEN(5) VALUE(' 1253')
DCL VAR(&amp;B2) TYPE(*CHAR) LEN(2)
CHGVAR %BINARY(&amp;B2) VALUE(&amp;C5)</pre>
<p>The character number 1253 in character variable &amp;C5 is
converted to a decimal number. The decimal number 1253 is then converted
to a 2-byte signed binary integer and stored in the variable &amp;B2. The
variable &amp;B2 will then have the value <span>X'04E5'</span>.</p>
</li>
<li> <pre>DCL VAR(&amp;S) TYPE(*CHAR) LEN(100)
IF (%BIN(&amp;S 1 2) *GT 10)
THEN( SNDPGMMSG MSG('Too many in list.') )</pre>
<p>The first 2 bytes of the character variable &amp;S are treated
as a signed binary integer when compared to the number 10. If the binary
number has a value larger than 10, then the <span class="cmdname">Send Program Message
(SNDPGMMSG)</span> command is run.</p>
</li>
<li> <pre>DCL VAR(&amp;RTNV) TYPE(*CHAR) LEN(4)
CALLPRC PRC(PROCA) RTNVAL(%BIN(&amp;RTNV 1 4))</pre>
<p>Procedure PROCA returns a 4-byte integer which is stored in
variable &amp;RTNV.</p>
</li>
</ul>
</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/if.htm">If (IF) command</a></div>
<div><a href="../cl/chgvar.htm">Change Variable (CHGVAR) command</a></div>
<div><a href="../cl/callprc.htm">Call Bound Procedure (CALLPRC) command</a></div>
<div><a href="../cl/sndpgmmsg.htm">Send Program Message (SNDPGMMSG) command</a></div>
</div>
</div>
</body>
</html>