NET/MASTER Network Control Language (NCL) Programmer's Guide
Terminating Execution of the Current Procedure or Function
Procedures and Functions
106160 Tandem Computers Incorporated 6–15
The RETURN Statement—
Procedures and Functions
The RETURN core statement terminates the execution of a procedure or function.
Using the RETURN Statement in Procedures
Using the RETURN core statement in a procedure is optional. It is used to return a list
of variables to the calling procedure or function.
If variables have been passed to a procedure, you can use the RETURN statement to
supplement the list of variables returned to the calling procedure. If no variables have
been passed to a procedure, you can use the RETURN statement to return a list of
variables created in the callee procedure. You cannot enclose the list of variables in
parentheses (parentheses are used by functions).
The following example shows an NCL procedure that uses the RETURN core
statement to terminate execution and supplement the current share list:
zex0608n: PROCEDURE
/* Uses RETURN in a procedure */
SAY Top level
&v1 = It is a
&v2 = SUNNY
&v3 = day today
SAY &v1 &v2 &v3 &newvar
/* Share all variables beginning with &V */
CALL first_level SHARE &v*
first_level: PROCEDURE
SAY First level
&v2 = RAINY
&newvar = so I need an umbrella
/* Use RETURN to supplement share list */
RETURN &newvar
END first_level
SAY Top level
SAY &v1 &v2 &v3 &newvar
END zex0608n
The top-level procedure explicitly assigns values to three variables, &V1, &V2, and
&V3. It uses a SAY statement to display the values of the variables. (&NEWVAR has
a null value at this point.) The top-level procedure then uses the SHARE keyword to
share all variables beginning with &V (not &NEWVAR) to the first-level procedure.
The first-level procedure alters the value of &V2 and explicitly assigns a value to
&NEWVAR. When the first-level procedure terminates execution, the value of &V2 is
automatically passed back to the top-level procedure. However, the first-level
procedure must use a RETURN statement to return &NEWVAR to the top-level
procedure. The final SAY statement shows the final result of sharing these variables.