NET/MASTER Network Control Language (NCL) Programmer's Guide

Explicit Branching
Controlling Execution Flow
5–36 106160 Tandem Computers Incorporated
The following example shows an NCL procedure that uses the GOSUB and RETSUB
statements:
zex0524n: PROCEDURE
/* GOSUB and RETSUB statements */
SAY "Initial value of &SYS.RETCODE is "&SYS.RETCODE
DO &taskno = 1 to 5
GOSUB task&taskno
SAY "Loop "&taskno" &SYS.RETCODE is "&SYS.RETCODE
END
SAY "Final value of &SYS.RETCODE is "&SYS.RETCODE
EXIT
task1:
SAY "Performs task "&taskno
RETSUB &taskno
task2:
task3:
SAY "Performs task "&taskno
RETSUB &taskno
task4:task5:task6:
SAY "Performs task "&taskno
RETSUB &taskno
END zex0524n
The procedure uses a DO loop to dynamically generate the target labels to which the
enclosed GOSUB statement jumps. After each subroutine completes its task, its
RETSUB statement returns a return code that is placed in the system variable
&SYS.RETCODE. The procedure terminates when it exits the DO loop.
The following screen shows the results of executing the procedure:
(12:28) --------------------- OPERATOR CONTROL SERVICES ----------------------
START ZEX0524N
Initial value of &SYS.RETCODE is 0
Performs task 1
Loop 1 &SYS.RETCODE is 1
Performs task 2
Loop 2 &SYS.RETCODE is 2
Performs task 3
Loop 3 &SYS.RETCODE is 3
Performs task 4
Loop 4 &SYS.RETCODE is 4
Performs task 5
Loop 5 &SYS.RETCODE is 5
Final value of &SYS.RETCODE is 5
NNM1005 START ZEX0524N PROCESSING COMPLETE. NCLID 002020
_____________________________________________________________________________
---------- ------------------ NonStop NET/MASTER D30 ---------------- --------
M=>