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

103 lines
5.4 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="task" />
<meta name="DC.Title" content="Decimal length and precision errors" />
<meta name="abstract" content="This details errors that occur when a decimal value is passed with incorrect decimal length and precision." />
<meta name="description" content="This details errors that occur when a decimal value is passed with incorrect decimal length and precision." />
<meta name="DC.subject" content="error, decimal length, precision, decimal length error, precision error" />
<meta name="keywords" content="error, decimal length, precision, decimal length error, precision error" />
<meta name="DC.Relation" scheme="URI" content="comer.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="dperr" />
<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>Decimal length and precision errors</title>
</head>
<body id="dperr"><a name="dperr"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Decimal length and precision errors</h1>
<div><p>This details errors that occur when a decimal value is passed with
incorrect decimal length and precision.</p>
<div class="section"> <p>If a decimal value is passed with an incorrect decimal length
and precision (either too long or too short), a decimal data error (MCH1202)
occurs when the variable is referred to. In the following examples, the numeric
constant is passed as <samp class="codeph">LEN(15 5)</samp>, but is declared in the called
procedure or program as <samp class="codeph">LEN(5 2)</samp>. Numeric constants are
always passed as packed decimal <samp class="codeph">(15 5)</samp>. </p>
<pre>CALL PGMA PARM(123) /* CALLING PROG */
PGM PARM(&amp;A) /* PGMA */
DCL &amp;A *DEC (5 2)
.
.
.
IF (&amp;A *GT 0) THEN(...) /* MCH1202 OCCURS HERE */</pre>
<p>If a decimal variable had been declared with <samp class="codeph">LEN(5
2)</samp> in the calling program or procedure and the value had been passed
as a variable instead of as a constant, no error would occur.</p>
<p>If you
need to pass a numeric constant to a procedure or program and the procedure
or program is expecting a value with a length and precision other than <samp class="codeph">15
5</samp>, the constant can be coded in hexadecimal format. The following
CALL command shows how to pass the value <samp class="codeph">25.5</samp> to a program
variable that is declared as <samp class="codeph">LEN(5 2)</samp>: </p>
<pre>CALL PGMA PARM(X'02550F')</pre>
<p>If a decimal value is passed with the correct length but with
the wrong precision (number of decimal positions), the receiving procedure
or program interprets the value incorrectly. In the following example, the
numeric constant value (with length (15 5)) passed to the procedure is handled
as <samp class="codeph">25124.00</samp>. </p>
<pre>CALL PGMA PARM(25.124) /* CALLING PGM */
PGM PARM(&amp;A) /* PGMA */
DCL &amp;A *DEC (15 2) /* LEN SHOULD BE 15 5*/
.
.
.
ENDPGM</pre>
<p>These errors occur when the variable is first referred to,
not when it is passed or declared. In the next example, the called program
does not refer to the variable, but instead simply places a value (of the
detected wrong length) in the variable returned to the calling program. The
error is not detected until the variable is returned to the calling program
and first referred to. This kind of error can be especially difficult to
detect. </p>
<pre>PGM /* PGMA */
DCL &amp;A *DEC (7 2)
CALL PGMB PARM(&amp;A) /* (7 2) PASSED TO PGMB */
IF (&amp;A *NE 0) THEN(...) /* *MCH1202 OCCURS HERE */
.
.
.
ENDPGM</pre>
<pre>PGM PARM(&amp;A) /* PGMB */
DCL &amp;A *DEC (5 2) /* WRONG LENGTH */
.
.
.
CHGVAR &amp;A (&amp;B-&amp;C) /* VALUE PLACED in &amp;A */
RETURN
When control returns to program PGMA and &amp;A is referred to, the error occurs.</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="comer.htm" title="This describes the errors encountered most frequently in passing values on a CALL command or a CALLPRC command. Some of these errors can be very difficult to debug, and some have serious consequences for program functions.">Common errors when calling programs and procedures</a></div>
</div>
</div>
</body>
</html>