ibm-information-center/dist/eclipse/plugins/i5OS.ic.cl_5.4.0.1/callprc.htm

272 lines
14 KiB
HTML

<!doctype html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Call Bound Procedure (CALLPRC)</title>
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body bgcolor="white">
<script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<a name="CALLPRC.Top_Of_Page"></a>
<h2>Call Bound Procedure (CALLPRC)</h2>
<table width="100%">
<tr>
<td valign="top" align="left"><b>Where allowed to run: </b>
<ul><li>Batch ILE CL module (*BMOD)</li>
<li>Interactive ILE CL module (*IMOD)</li>
</ul><b>Threadsafe: </b>Yes
</td>
<td valign="top" align="right">
<a href="#CALLPRC.PARAMETERS.TABLE">Parameters</a><br>
<a href="#CALLPRC.COMMAND.EXAMPLES">Examples</a><br>
<a href="#CALLPRC.ERROR.MESSAGES">Error messages</a></td>
</tr>
</table>
<div> <a name="CALLPRC"></a>
<p>The Call Bound Procedure (CALLPRC) command calls a bound procedure named on the command, and passes control to it. Optionally, the procedure issuing the CALLPRC command can pass parameters to the called procedure. The CALLPRC command can be used in compiled ILE control language (CL) programs and modules. If the called procedure returns a value, such as an error code, the returned value can be stored into a CL variable by specifying the CL variable name for the <b>CL variable for returned value (RTNVAL)</b> parameter.
</p>
<p>Each parameter value passed to the called procedure can be a character string constant, a numeric constant, a logical constant, a floating-point constant, or a CL variable. If a floating-point constant is specified, the value is converted to double-precision format and passed to the called program. If parameters are passed, the value of the constant or variable is available to the program that is called. Parameters cannot be passed in any of the following forms: lists of values, qualified names, expressions, or keyword parameters. Up to 300 parameters can be passed to the called procedure.
</p>
<p>
<b>Note: </b>Although the CALLPRC command will allow up to 300 parameters to be passed, the number that the called procedure can accept will depend on the language of the called procedure. For example, a CL procedure cannot accept more than 255 parameters.
</p>
<p>If parameters are passed to a procedure using the CALLPRC command, the values of the parameters are passed in the order in which they appear on the CALLPRC command; this order must match the order in which they appear in the parameter list in the called procedure.
</p>
<p>Parameters may be passed <b>by reference</b> or passed <b>by value</b>.
</p>
<p><b>Restrictions:</b>
</p>
<ul>
<li>The CALLPRC command is valid only within an ILE CL module.
</li>
</ul>
</div>
<table width="100%">
<tr><td align="right"><a href="#CALLPRC.Top_Of_Page">Top</a></td></tr>
</table>
<hr size="2" width="100%">
<div>
<h3><a name="CALLPRC.PARAMETERS.TABLE">Parameters</a></h3>
<table border="1" cellpadding="4" cellspacing="0">
<!-- col1="10" col2="15" col3="30" col4="10" -->
<tr>
<th bgcolor="aqua" valign="bottom" align="left">Keyword</th>
<th bgcolor="aqua" valign="bottom" align="left">Description</th>
<th bgcolor="aqua" valign="bottom" align="left">Choices</th>
<th bgcolor="aqua" valign="bottom" align="left">Notes</th>
</tr>
<tr>
<td valign="top"><a href="#CALLPRC.PRC"><b>PRC</b></a></td>
<td valign="top">Procedure</td>
<td valign="top"><i>Character value</i></td>
<td valign="top">Required, Positional 1</td>
</tr>
<tr>
<td valign="top" rowspan="3"><a href="#CALLPRC.PARM"><b>PARM</b></a></td>
<td valign="top">Parameters</td>
<td valign="top">Values (up to 300 repetitions): <i>Element list</i></td>
<td valign="top" rowspan="3">Optional, Positional 2</td>
</tr>
<tr>
<td valign="top">Element 1: Parameter</td>
<td valign="top">
<i>Not restricted</i></td>
</tr>
<tr>
<td valign="top">Element 2: Passed</td>
<td valign="top">
<b><u>*BYREF</u></b>, *BYVAL</td>
</tr>
<tr>
<td valign="top"><a href="#CALLPRC.RTNVAL"><b>RTNVAL</b></a></td>
<td valign="top">CL variable for returned value</td>
<td valign="top"><i>CL variable name</i>, <b><u>*NONE</u></b></td>
<td valign="top">Optional, Positional 3</td>
</tr>
</table>
<table width="100%">
<tr><td align="right"><a href="#CALLPRC.Top_Of_Page">Top</a></td></tr>
</table>
</div>
<div> <a name="CALLPRC.PRC"></a>
<h3>Procedure (PRC)</h3>
<p>Specifies the name of the procedure to be called.
</p>
<dl>
<dt><b><i>name</i></b></dt>
<dd>Specify the name of the procedure to be called. The procedure must be in the same program as the calling procedure or in a service program specified at the time the calling program was created. The procedure name may be up to 256 bytes long. The procedure name will be case sensitive. A CL variable cannot be specified for the procedure name.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#CALLPRC.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="CALLPRC.PARM"></a>
<h3>Parameters (PARM)</h3>
<p>Specifies parameter values that are to be passed to the called procedure. Passing parameters is optional; if no parameters are specified, no parameters will be passed to the called procedure. Up to 300 parameters can be specified.
</p>
<p><b>Element 1: Parameter</b>
</p>
<dl>
<dt><b>*OMIT</b></dt>
<dd>The parameter is omitted. A null pointer is to be passed to the called procedure. When *OMIT is specified for element 1, you cannot specify *BYVAL for element 2.
</dd>
<dt><b><i>parameter-value</i></b></dt>
<dd>Specify a value that is to be passed to the called procedure as a parameter. The parameter value can be specified as a character string constant, a numeric constant, a logical constant, a double-precision floating point constant, or a CL variable.
<p>The type and length of each parameter must be the same in both the calling and called procedures. The order in which parameters are sent and received must also be the same. The number of parameters specified by the calling procedure does not have to match the number of parameters specified by the called procedure. If the calling procedure specifies more parameters than are defined in the called procedure, the extra parameters are ignored. If the calling procedure specifies fewer parameters than are defined in the called procedure, and the called procedure references the missing parameters, runtime results will be unpredictable.
</p>
<p>Parameters can be passed and received as follows:
</p>
<ul>
<li>Character string constants are neither padded with blanks or null terminated. The operational descriptor for the parameter will have the length of the string.
<p>The called procedure can receive less than the number of bytes passed (in this case, no message is sent). For example, if a called procedure specifies that 4 characters are to be received and ABCDEF is passed, only ABCD is accepted and used by the called procedure. Quoted character strings can also be passed.
</p>
</li>
<li>Decimal constants are passed in packed form and with a length of (15 5), where the value is 15 digits long, of which 5 digits are decimal positions. If a parameter of 12345 is passed, the called procedure must declare the decimal field as (15 5); the parameter is received as 1234500000 (which is 12,345.00000).
</li>
<li>Logical constants are passed as 1 byte with a logical value of 'F1'X or 'F0'X.
</li>
<li>Floating-point literals and floating-point special values (*NAN, *INF, and *NEGINF) are passed as double-precision floating-point numbers in IEEE format, which occupy 8 bytes and are specified in the form sn.nEsn; where s is a plus sign (+) or a minus sign(-); for example, -2.47E+3 or 3.653E24. A single-precision floating-point number cannot be passed to a called procedure.
</li>
<li>A CL variable can be passed, in which case the called procedure must declare the field to match the variable defined in the calling procedure. For example, if a CL procedure defines a decimal variable named &amp;CHKNUM as (5 0), the called procedure must declare the field as packed with 5 digits total, with no decimal positions.
<p>If either a decimal constant or a program variable can be passed to the called procedure, the parameter should be defined as (15 5), and any calling procedure must adhere to that definition. If the type, number, order, and length of the parameters do not match between the calling and called procedures (other than the length exception noted previously for character constants), unpredictable results will occur.
</p>
</li>
<li>Operational descriptors will always be built for character arguments passed on the PARM keyword. The called procedure can use the information in the descriptor to determine the length of the argument. For character string constants, the length will be the actual length of the constant. For character variables, the length will be the declared length of the variable.
</li>
</ul>
</dd>
</dl>
<p><b>Element 2: Passed</b>
</p>
<dl>
<dt><b><u>*BYREF</u></b></dt>
<dd>The parameter is to be passed <b>by reference</b>. Passing a parameter by reference means that the actual parameter is a pointer which points to storage in the calling procedure which contains the CL variable or constant value. If the called procedure is a CL procedure, all parameters must be passed by reference. If a CL variable is passed by reference, the called procedure can change its value and the change is reflected in the calling procedure. If a constant is passed by reference, a copy of the constant is made in the calling procedure and a pointer to that copy is passed to the called procedure.
</dd>
<dt><b>*BYVAL</b></dt>
<dd>The parameter is to be passed <b>by value</b>. Passing a parameter by value means that the called procedure receives a copy of the parameter. If the parameter is a CL variable, changes made to the parameter by the called procedure do not change the CL variable in the calling procedure. The called procedure must be defined to receive a parameter that is passed by value.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#CALLPRC.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="CALLPRC.RTNVAL"></a>
<h3>CL variable for returned value (RTNVAL)</h3>
<p>Specifies the variable to contain the return value from the called procedure. If the value returned by the called procedure is a binary number (types <b>int</b> or <b>short</b> in ILE C or ILE C++), you must either specify an integer CL variable (specified as TYPE(*INT) or TYPE(*UINT) on the DCL statement) or use the %BINARY or %BIN built-in function on a character CL variable (specified as TYPE(*CHAR) on the DCL statement) used for the return value parameter.
</p>
<dl>
<dt><b><u>*NONE</u></b></dt>
<dd>The called procedure does not return a value.
</dd>
<dt><b><i>CL-variable-name</i></b></dt>
<dd>Specify the name of the CL variable that is to contain the return value from the called procedure. This may be a decimal, integer, or character CL variable. Variables used as return variables will automatically be aligned on a 16-byte boundary.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#CALLPRC.Top_Of_Page">Top</a></td></tr>
</table>
<hr size="2" width="100%">
<div><h3><a name="CALLPRC.COMMAND.EXAMPLES">Examples</a> </h3>
<p><b>Example 1: Calling a Procedure</b>
</p>
<p>
<pre>
CALLPRC PRC(PAYROLL)
</pre>
</p>
<p>The procedure named PAYROLL is called with no parameters being passed to it. The PAYROLL procedure does not return a value.
</p>
<p><b>Example 2: Passing a Character Constant</b>
</p>
<p>
<pre>
CALLPRC PRC(PAYROLL) PARM('1')
</pre>
</p>
<p>The procedure named PAYROLL is called with a character constant passed as a quoted string. The PAYROLL procedure does not return a value.
</p>
<p><b>Example 3: Passing Parameters</b>
</p>
<p>
<pre>
CALLPRC PRC(PAYROLL) PARM(CHICAGO 1234 &amp;VAR1)
RTNVAL(*NONE)
</pre>
</p>
<p>The procedure named PAYROLL is called. The calling procedure passes three parameters: a character string (CHICAGO), a decimal value (1234.00000), and the contents of the CL variable &amp;VAR1. The attributes of the variable determine the attributes of the third parameter. The PAYROLL procedure does not return a value.
</p>
<p><b>Example 4: Calling Procedure with Floating-Point Values</b>
</p>
<p>
<pre>
CALLPRC PRC(PRC1) PARM(1.5E3 *INF) RTNVAL(&amp;RVAL)
</pre>
</p>
<p>The procedure named PRC1 is called with two double-precision floating-point values being passed to it. The returned value is stored in variable &amp;RVAL.
</p>
<p><b>Example 5: Ignoring the Return Value of a Procedure</b>
</p>
<p>
<pre>
CALLPRC PRC(PRC1) PARM(1.5E3 *INF) RTNVAL(*NONE)
</pre>
</p>
<p>The procedure named PRC1 is called with two double-precision floating-point values being passed to it. The returned value is ignored and therefore unavailable to the calling procedure.
</p>
<p><b>Example 6: Calling a Procedure that Returns a Binary Number Using %BIN</b>
</p>
<p>
<pre>
CALLPRC PRC(RTNINT) RTNVAL(%BIN(&amp;RTNV 1 4))
</pre>
</p>
<p>The procedure named RTNINT returns a 4-byte binary value. It is stored in the first four bytes of variable &amp;RTNV. Variable &amp;RTNV is of type *CHAR and has a length of at least 4.
</p>
<p><b>Example 7: Calling a Procedure that Returns a Binary Number Using an Integer CL Variable</b>
</p>
<p>
<pre>
DCL VAR(&amp;VAR2) TYPE(*INT) LEN(4)
:
CALLPRC PRC(RTNINT) RTNVAL(&amp;VAR2)
</pre>
</p>
<p>The procedure named RTNINT returns a 4-byte binary value, which is stored in the 4-byte signed integer CL variable &amp;VAR2.
</p>
<p><b>Example 8: Calling a Procedure Passing a Parameter By Value</b>
</p>
<p>
<pre>
DCL VAR(&amp;POS) TYPE(*INT) LEN(2)
:
CALLPRC PRC(SCAN_STRING) PARM((&amp;STR1 *BYREF) (' ' *BYVAL))
RTNVAL(&amp;POS)
</pre>
</p>
<p>The procedure named SCAN_STRING is called with two parameters. The CL variable &amp;STR1 is passed <b>by reference</b> and the constant character string ' ' (one blank) is passed <b>by value</b> to SCAN_STRING. Procedure SCAN_STRING must be defined to receive the first parameter as a pointer to a character string and the second parameter as a one-byte character string. The SCAN_STRING procedure returns a 2-byte binary value, which is stored in the 2-byte signed integer CL variable &amp;POS.
</p>
</div>
<table width="100%">
<tr><td align="right"><a href="#CALLPRC.Top_Of_Page">Top</a></td></tr>
</table>
<hr size="2" width="100%">
<div><h3><a name="CALLPRC.ERROR.MESSAGES">Error messages</a> </h3>
<p><b><u>*ESCAPE Messages</u></b>
</p>
<dl>
<dt><b>CPF0806</b></dt>
<dd>Error found when procedure started.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#CALLPRC.Top_Of_Page">Top</a></td></tr>
</table>
</body>
</html>