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

100 lines
6.5 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="reference" />
<meta name="DC.Title" content="SUBR command and Subroutines" />
<meta name="abstract" content="The Subroutine (SUBR) command is used in a CL procedure, along with the End Subroutine (ENDSUBR) command, to delimit the group of commands that define a subroutine." />
<meta name="description" content="The Subroutine (SUBR) command is used in a CL procedure, along with the End Subroutine (ENDSUBR) command, to delimit the group of commands that define a subroutine." />
<meta name="DC.subject" content="Subroutine (SUBR) command, command, CL, SUBR command, Subroutine command, subroutine" />
<meta name="keywords" content="Subroutine (SUBR) command, command, CL, SUBR command, Subroutine command, subroutine" />
<meta name="DC.Relation" scheme="URI" content="contp.htm" />
<meta name="DC.Relation" scheme="URI" content="callsubrc.htm" />
<meta name="DC.Relation" scheme="URI" content="../clfinder/finder.htm" />
<meta name="DC.Relation" scheme="URI" content="../cl/subr.htm" />
<meta name="DC.Relation" scheme="URI" content="../cl/endsubr.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="subrc" />
<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>SUBR command and Subroutines</title>
</head>
<body id="subrc"><a name="subrc"><!-- --></a>
<img src="./delta.gif" alt="Start of change" /><!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">SUBR command and Subroutines</h1>
<div><p>The <span class="cmdname">Subroutine (SUBR)</span> command is used in a CL
procedure, along with the <span class="cmdname">End Subroutine (ENDSUBR)</span> command,
to delimit the group of commands that define a subroutine. </p>
<div class="section"><p>The name of the subroutine, as used by the CALLSUBR command, is
defined by the SUBR parameter on the <span class="cmdname">Subroutine (SUBR)</span> command.</p>
<p>The
first <span class="cmdname">Subroutine (SUBR)</span> command that is encountered in
a procedure also marks the end of the mainline of that procedure. All commands
from this point forward, with the exception of the ENDPGM command, must be
contained within a subroutine, in other words, between <span class="cmdname">Subroutine
(SUBR)</span> and <span class="cmdname">End Subroutine (ENDSUBR)</span> commands.
The <span class="cmdname">Subroutine (SUBR)</span> and <span class="cmdname">End Subroutine (ENDSUBR)</span> commands
must be matched pairs, and subroutines cannot be nested; in other words, no
SUBR SUBR - ENDSUBR ENDSUBR nesting of subroutines is allowed.</p>
<p>Both
the ENDSUBR and RTNSUBR commands can be used to exit a subroutine, and when
processed, control is returned to the command immediately following the <span class="cmdname">Call
Subroutine (CALLSUBR)</span> command that called the subroutine. Both commands
have an optional RTNVAL parameter, which can be anything that can be stored
in a CL variable of TYPE(*INT) and LEN(4). If no RTNVAL parameter is defined
on the <span class="cmdname">Return Subroutine (RTNSUBR)</span> or <span class="cmdname">End Subroutine
(ENDSUBR)</span> command, a value of zero is returned.</p>
<p> For an example
of the general structure of a CL procedure which contains a subroutine, see
the following:</p>
<pre> PGM
DCLPRCOPT SUBRSTACK(25)
DCL VAR(&amp;RTNVAR) TYPE(*INT) LEN(4)
:
CALLSUBR SUBR(SUBR1) RTNVAL(&amp;RTNVAR)
:
SUBR SUBR(SUBR1)
:
RTNSUBR RTNVAL(-1)
:
ENDSUBR
ENDPGM </pre>
<p>In this example, the <span class="cmdname">Declare
Processing Options (DCLPRCOPT)</span> command was used to specify the size
of the subroutine stack to be 25. The variable &amp;RTNVAR is used to contain
the return value from the subroutine. The <span class="cmdname">Call Subroutine (CALLSUBR)</span> command
will transfer control to the subroutine SUBR1, as defined by the SUBR command.
If the <span class="cmdname">Return Subroutine (RTNSUBR)</span> command is run, the
value of &amp;RTNVAR will be -1, if the <span class="cmdname">End Subroutine (ENDSUBR)</span> command
is run, &amp;RTNVAR will equal 0. If no RTNVAL parameter was defined on the <span class="cmdname">Call
Subroutine (CALLSUBR)</span> command, the return value from the subroutine
would be ignored.</p>
</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="relref"><strong>Related reference</strong><br />
<div><a href="callsubrc.htm" title="The Call Subroutine (CALLSUBR) command is used in a CL procedure for passing control to a subroutine defined within the same procedure.">CALLSUBR command</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/subr.htm">Subroutine (SUBR) command</a></div>
<div><a href="../cl/endsubr.htm">End Subroutine (ENDSUBR) command</a></div>
</div>
</div>
<img src="./deltaend.gif" alt="End of change" /></body>
</html>