<?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="CALLSUBR command" /> <meta name="abstract" content="The Call Subroutine (CALLSUBR) command is used in a CL procedure for passing control to a subroutine defined within the same procedure." /> <meta name="description" content="The Call Subroutine (CALLSUBR) command is used in a CL procedure for passing control to a subroutine defined within the same procedure." /> <meta name="DC.subject" content="Call Subroutine (CALLSUBR) command, command, CL, Call Subroutine (CALLSUBR), example, CALLSUBR command" /> <meta name="keywords" content="Call Subroutine (CALLSUBR) command, command, CL, Call Subroutine (CALLSUBR), example, CALLSUBR command" /> <meta name="DC.Relation" scheme="URI" content="contp.htm" /> <meta name="DC.Relation" scheme="URI" content="subrc.htm" /> <meta name="DC.Relation" scheme="URI" content="../cl/dclprcopt.htm" /> <meta name="DC.Relation" scheme="URI" content="../clfinder/finder.htm" /> <meta name="DC.Relation" scheme="URI" content="../cl/callsubr.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="callsubrc" /> <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>CALLSUBR command</title> </head> <body id="callsubrc"><a name="callsubrc"><!-- --></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">CALLSUBR command</h1> <div><p>The <span class="cmdname">Call Subroutine (CALLSUBR)</span> command is used in a CL procedure for passing control to a subroutine defined within the same procedure.</p> <div class="section"><p>The <span class="cmdname">Call Subroutine (CALLSUBR)</span> command has two parameters: <span class="cmdname">Subroutine (SUBR)</span>, which contains the name of the subroutine to which control is to be transferred to, and <span class="cmdname">Return value (RTNVAL)</span>, which specifies the variable that will contain the return value from the called subroutine. See the following example:</p> <pre>CALLSUBR SUBR(mysubr) RTNVAL(&myrtnvar)</pre> <p>The subroutine <samp class="codeph">mysubr</samp> must be defined in the procedure by the Subroutine (SUBR) parameter of a <span class="cmdname">Subroutine (SUBR)</span> command. The variable '&myrtnvar' must be defined as TYPE(*INT) LEN(4), and will contain the value from the Return value (RTNVAL) parameter of either a <span class="cmdname">Return from Subroutine (RTNSUBR)</span> or the <span class="cmdname">End Subroutine (ENDSUBR)</span> command found in subroutine 'mysubr'. If no RTNVAL parameter is defined, the return value from the subroutine is ignored.</p> <p>The <span class="cmdname">Call Subroutine (CALLSUBR)</span> command may be placed anywhere within the procedure, including other subroutines, with the exception of a program-level <span class="cmdname">Monitor Message (MONMSG)</span> command. Each <span class="cmdname">Call Subroutine (CALLSUBR)</span> command, when run, places a return address onto the subroutine stack, and the size of the stack can be changed with the use of the Subroutine Stack (SUBRSTACK) parameter of the <span class="cmdname">Declare Process Options (DCLPRCOPT)</span> command. If a globally monitored message causes a GOTO command to be run, the subroutine stack will be reset by the next <span class="cmdname">Call Subroutine (CALLSUBR)</span> command that is run. See the following example:</p> <pre> PGM DCL VAR(&myrtnvar) TYPE(*INT) LEN(4) MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(DUMP)) : CALLSUBR SUBR(SUBR1) RTNVAL(&myrtnvar) : DUMP: DMPCLPGM CALLSUBR SUBR(SUBR2) : SUBR SUBR(SUBR1) : SUBR SUBR(SUBR1) : ENDSUBR RTNVAL(12) : SUBR SUBR(SUBR2) : ENDSUBR ENDPGM </pre> <p>In this example, the first <span class="cmdname">Call Subroutine (CALLSUBR)</span> command will pass control to the subroutine SUBR1, and the return value of <samp class="codeph">12</samp> will be placed into the variable <samp class="codeph">&myrtnvar</samp> when control returns. If a message is monitored by the <span class="cmdname">Monitor Message (MONMSG)</span> command, the <span class="cmdname">Goto (GOTO)</span> command will be run and control will branch to label DUMP, the CL procedure will be dumped by DMPCLPGM, and the next CALLSUBR to subroutine SUBR2 will reset the subroutine stack.</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="subrc.htm" title="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.">SUBR command and Subroutines</a></div> </div> <div class="relinfo"><strong>Related information</strong><br /> <div><a href="../cl/dclprcopt.htm">Declare (DCLPRCOPT) command</a></div> <div><a href="../clfinder/finder.htm">CL command finder</a></div> <div><a href="../cl/callsubr.htm">Call Subroutine (CALLSUBR) command</a></div> </div> </div> <img src="./deltaend.gif" alt="End of change" /></body> </html>