124 lines
6.8 KiB
HTML
124 lines
6.8 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="task" />
|
|
<meta name="DC.Title" content="Character length errors" />
|
|
<meta name="abstract" content="This details errors that occur when you pass character values with incorrect length." />
|
|
<meta name="description" content="This details errors that occur when you pass character values with incorrect length." />
|
|
<meta name="DC.subject" content="error, character length, character length error, CALLPRC (Call Procedure) command, example, command, CL, CALLPRC (Call Procedure), calling, description, calling procedure, CALLPRC command example" />
|
|
<meta name="keywords" content="error, character length, character length error, CALLPRC (Call Procedure) command, example, command, CL, CALLPRC (Call Procedure), calling, description, calling procedure, CALLPRC command example" />
|
|
<meta name="DC.Relation" scheme="URI" content="comer.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="../cl/callprc.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="../cl/call.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="clerr" />
|
|
<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>Character length errors</title>
|
|
</head>
|
|
<body id="clerr"><a name="clerr"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Character length errors</h1>
|
|
<div><p>This details errors that occur when you pass character values with
|
|
incorrect length.</p>
|
|
<div class="section"> <p>If you pass a character value longer than the declared character
|
|
length of the receiving variable, the receiving procedure or program cannot
|
|
access the excess length. In the following example, PGMB changes the variable
|
|
that is passed to it to blanks. Because the variable is declared with <samp class="codeph">LEN(5</samp>),
|
|
only 5 characters are changed to blanks in PGMB, but the remaining characters
|
|
are still part of the value when referred to in PGMA. </p>
|
|
<pre>PGM /* PGMA */
|
|
DCL &A *CHAR 10
|
|
CHGVAR &A 'ABCDEFGHIJ'
|
|
CALL PGMB PARM(&A) /* PASS to PGMB */
|
|
.
|
|
.
|
|
.
|
|
IF (&A *EQ ' ') THEN(...) /* THIS TEST FAILS */
|
|
ENDPGM
|
|
|
|
PGM PARM(&A) /* PGMB */
|
|
DCL &A *CHAR 5 /* THIS LEN ERROR*/
|
|
CHGVAR &A ' ' /* 5 POSITIONS ONLY; OTHERS UNAFFECTED */
|
|
RETURN</pre>
|
|
<p>While this kind of error does not cause an escape message,
|
|
variables handled this way may function differently than expected.</p>
|
|
<p>If
|
|
the value passed to a procedure or program is shorter than its declared length
|
|
in the receiving procedure or program, there may be more serious consequences.
|
|
In this case, the value of the variable in the called procedure or program
|
|
consists of its values as originally passed, and whatever follows that value
|
|
in storage, up to the length declared in the called procedure or program.
|
|
The content of this adopted storage cannot be predicted. If the passed value
|
|
is a variable, it could be followed by other variables or by internal control
|
|
structures for the procedure or program. If the passed value is a constant,
|
|
it could be followed in storage by other constants passed on the CALL or CALLPRC
|
|
command or by internal control structures.</p>
|
|
<p>If the receiving procedure
|
|
or program changes the value, it operates on the original value and on the
|
|
adopted storage. The immediate effect of this could be to change other variables
|
|
or constants, or to change internal structures in such a way that the procedure
|
|
or program fails. Changes to the adopted storage take effect immediately.</p>
|
|
<p>In
|
|
the following example, two 3-character constants are passed to the called
|
|
program. Character constants are passed with a minimum of 32 characters for
|
|
the <span class="cmdname">Call (CALL)</span> command. (Normally, the value is passed
|
|
as 3 characters left-adjusted with trailing blanks.) If the receiving program
|
|
declares the receiving variable to be longer than 32 positions the extra positions
|
|
use adopted storage of unknown value. For this example, assume that the two
|
|
constants are adjacent in storage.</p>
|
|
<pre>CALL PGMA ('ABC' 'DEF') /* PASSING PROG */
|
|
|
|
PGM PARM(&A &B) /* PGMA */
|
|
DCL &A *CHAR 50 /* VALUE:ABC+29' '+DEF+15' ' */
|
|
DCL &B *CHAR 10 /* VALUE:DEF+7' ' */
|
|
CHGVAR VAR(&A) (' ') /* THIS ALSO BLANKS &B */
|
|
.
|
|
.
|
|
.
|
|
ENDPGM</pre>
|
|
<p>Values passed as variables behave in exactly the same way.</p>
|
|
<p>In
|
|
the following example, two 3-character constants are passed to the called
|
|
procedure. Only the number of characters specified are passed for the <span class="cmdname">Call
|
|
Procedure (CALLPRC)</span> command. If the receiving program
|
|
declares the receiving variable to be longer than the length of the passed
|
|
constant, the extra positions use adopted storage of unknown value.</p>
|
|
<p>In
|
|
the following example, assume the two constants are adjacent in storage.</p>
|
|
<pre>CALLPRC PRCA ('ABC' 'DEF') /* PASSING PROG */
|
|
|
|
PGM PARM(&A &B) /* *PRCA */
|
|
DCL &A *CHAR 5 /* VALUE:'ABC' + 'DE' */
|
|
DCL &B *CHAR 3 /* VALUE:'DEF' */
|
|
CHGVAR &A ' ' /* This also blanks the first two bytes of &B */
|
|
.
|
|
.
|
|
.
|
|
ENDPGM</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 class="relinfo"><strong>Related information</strong><br />
|
|
<div><a href="../cl/callprc.htm">Call Bound Procedure (CALLPRC) command</a></div>
|
|
<div><a href="../cl/call.htm">Call (CALL) command</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |