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

139 lines
5.6 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 Subroutine (CALLSUBR)</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="CALLSUBR.Top_Of_Page"></a>
<h2>Call Subroutine (CALLSUBR)</h2>
<table width="100%">
<tr>
<td valign="top" align="left"><b>Where allowed to run: </b>
<ul><li>Batch program (*BPGM)</li>
<li>Interactive program (*IPGM)</li>
</ul><b>Threadsafe: </b>Yes
</td>
<td valign="top" align="right">
<a href="#CALLSUBR.PARAMETERS.TABLE">Parameters</a><br>
<a href="#CALLSUBR.COMMAND.EXAMPLES">Examples</a><br>
<a href="#CALLSUBR.ERROR.MESSAGES">Error messages</a></td>
</tr>
</table>
<div> <a name="CALLSUBR"></a>
<p>The Call Subroutine (CALLSUBR) command is used in CL procedures for passing control to a subroutine. The subroutine name on the CALLSUBR command must match the subroutine name of a SUBR (Subroutine) command. The CALLSUBR command may be placed anywhere within the procedure, including other subroutines, with the exception of a program-level MONMSG command. If the called subroutine returns a value, such as an error code, the returned value can be stored into a 4-byte integer CL variable by specifying the CL variable name for the <b>CL variable for returned value (RTNVAL)</b> parameter.
</p>
<p>Each CALLSUBR command which is run places a return address on the subroutine stack. A return address is removed from the subroutine stack when a RTNSUBR (Return from Subroutine) or ENDSUBR (End Subroutine) command is run. The default depth of the subroutine stack is 99. The subroutine stack depth can be set for a CL procedure by using the the DCLPRCOPT (Declare Processing Options) command, and specifying a value for the <b>Subroutine stack depth (SUBRSTACK)</b> parameter. If a CALLSUBR command would cause the subroutine stack depth limit to be exceeded, message CPF0822 is issued and the subroutine stack is not changed.
</p>
<p><b>Restrictions:</b> This command is valid only within a CL procedure.
</p>
</div>
<table width="100%">
<tr><td align="right"><a href="#CALLSUBR.Top_Of_Page">Top</a></td></tr>
</table>
<hr size="2" width="100%">
<div>
<h3><a name="CALLSUBR.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="#CALLSUBR.SUBR"><b>SUBR</b></a></td>
<td valign="top">Subroutine</td>
<td valign="top"><i>Simple name</i></td>
<td valign="top">Required, Positional 1</td>
</tr>
<tr>
<td valign="top"><a href="#CALLSUBR.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</td>
</tr>
</table>
<table width="100%">
<tr><td align="right"><a href="#CALLSUBR.Top_Of_Page">Top</a></td></tr>
</table>
</div>
<div> <a name="CALLSUBR.SUBR"></a>
<h3>Subroutine (SUBR)</h3>
<p>Specifies the subroutine to which control is to be transferred when the Call Subroutine (CALLSUBR) command is processed. The subroutine must be defined within the same procedure as the CALLSUBR command.
</p>
<p>This is a required parameter.
</p>
<dl>
<dt><b><i>simple-name</i></b></dt>
<dd>Specify the name of the subroutine to which control will be passed. A CL variable name cannot be used to specify the subroutine name.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#CALLSUBR.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="CALLSUBR.RTNVAL"></a>
<h3>CL variable for returned value (RTNVAL)</h3>
<p>Specifies the variable to receive the return value from the called subroutine.
</p>
<dl>
<dt><b><u>*NONE</u></b></dt>
<dd>The value returned by the subroutine is ignored.
</dd>
<dt><b><i>CL-variable-name</i></b></dt>
<dd>Specify the name of the CL variable to receive the return value from the called subroutine. The return value will either be the default of zero, or the value specified for the <b>Return value (RTNVAL)</b> parameter on the Return from Subroutine (RTNSUBR) or End Subroutine (ENDSUBR) command. The variable must be a 4-byte signed integer CL variable.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#CALLSUBR.Top_Of_Page">Top</a></td></tr>
</table>
<hr size="2" width="100%">
<div><h3><a name="CALLSUBR.COMMAND.EXAMPLES">Examples</a> </h3>
<p><b>Example 1: CALLSUBR with RTNVAL</b>
</p>
<p>
<pre>
DCL &amp;INT4VAR TYPE(*INT) LEN(4)
:
CALLSUBR SUBR(SUBR1) RTNVAL(&amp;INT4VAR)
</pre>
</p>
<p>The subroutine named SUBR1 is called, and the return value is stored in the variable &amp;INT4VAR
</p>
<p><b>Example 2: CALLSUBR as command parameter on IF command</b>
</p>
<p>
<pre>
IF (&amp;A *LT 30) THEN(CALLSUBR LT30)
</pre>
</p>
<p>The subroutine named LT30 is called if &amp;A is less than 30.
</p>
</div>
<table width="100%">
<tr><td align="right"><a href="#CALLSUBR.Top_Of_Page">Top</a></td></tr>
</table>
<hr size="2" width="100%">
<div><h3><a name="CALLSUBR.ERROR.MESSAGES">Error messages</a> </h3>
<p><b><u>*ESCAPE Messages</u></b>
</p>
<dl>
<dt><b>CPF0822</b></dt>
<dd>Subroutine stack overflow at statement &amp;1.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#CALLSUBR.Top_Of_Page">Top</a></td></tr>
</table>
</body>
</html>