# jCL GOSUB
Updated: 2/24/2021, 3:51:59 PM
Created: 2/24/2021, 3:51:59 PM
Last Updated By: Daniel Klein
Read Time: 1 minute(s)
Tags: go jcl
# Description
This command transfers control to a specific subroutine. It takes the general form:
GOSUB label
or
GOSUB label] label... (Multivalued form)
where label specifies the label, which marks the required subroutine.
# Note
When an RSUB statement is encountered, control is transferred back to the line immediately following the calling GOSUB .
# Multivalued Form
To use the multivalued form of the GOSUB command, you must specify one label for each result of a multiple comparison. For example:
IF %2 = A]B]C]D GOSUB 1000]2000]3000]4000
Separate the test values and the destination labels with value marks (ctrl ]).
Note that this is a special case of the GOSUB command. and should not be used where it is desired to have a mix of command types in the resulting actions. You can still achieve the same effect but each result must contain a separate command. For example:
IF %2 = A]B]" GOSUB 1000]GOSUB 2000]XFinished
In this case, if the result of the test for null is true the program will terminate with a suitable message.
# Example
010 GOSUB 1000
011 T "Returned from GOSUB"
...
...
031 1000 T "In subroutine"
032 IP %1
033 RSUB
2
3
4
5
6
7
8
9
The GOSUB command on line 10 transfers control to label 1000 on line 31. When the RSUB on line 33 is processed, control returns to line 11.
See also"[ ] {n}" command
Back to jCL.