# jCL GOSUB

Updated: 10/23/2020, 1:48:27 PM
Created: 10/23/2020, 1:48:27 PM
Last Updated By: Mike Street
Read Time: 1 minute(s)

Tags: go jcl

# Description

This command transfers control to a specific subroutine. It takes the general form:

GOSUB  label
1

or

GOSUB label] label... (Multivalued form)
1

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
1

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
1

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
1
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.