Previous Topic: &FNDSTR

Next Topic: &GOTO


&GOSUB

Branches to a sub-routine within the procedure.

&GOSUB .label [ .limlabel [ EQ | NE | GT | LT | GE | LE ] ]

The &GOSUB verb lets you structure a procedure to take advantage of common processing routines, called sub-routines. &GOSUB changes the current processing location within a procedure. Control transfers to the statement beginning with the specified target label. On completion of the sub-routine an &RETSUB statement resumes processing at the statement following the &GOSUB statement.

The label, after variable substitution, must begin with a period and is from 1 to 12 characters long (not including the period).

The target label can precede or follow the statement containing the &GOSUB.

Operands:

.label

A label within the procedure.

.limlabel

A label in the procedure that delimits the extent of the search for .label. If .limlabel is found before the required label .label is located, the search terminates with a 'label not found' condition. Use .limlabel to improve the performance of procedures where a large number of unexpected labels normally discarded by the &CONTROL NOLABEL are received. When used with the search scope (see next operand), .limlabel can assist with table processing.

EQ | NE | GT | LT | GE | LE

An optional search scope used to qualify the selection of a target label that satisfies the search for .label up to the range set by .limlabel. If this operand is required, then .limlabel must be specified. In cases where .limlabel is not required, enter it with the same value as .label.

If this operand is omitted, .limlabel must exactly equal a procedure label to terminate the search.

EQ

Specifies that the first label generically equal to .label will satisfy the search.

NE

Specifies that the first label generically not equal to .label will satisfy the search.

GT

Specifies that the first label greater than .label will satisfy the search.

LT

Specifies that the first label less than .label will satisfy the search.

GE

Specifies that the first label greater than or equal to .label will satisfy the search.

LE

Specifies that the first label less than or equal to .label will satisfy the search.

Examples: &GOSUB

.MAINLINE
   &GOSUB .INITIALIZE
   &DOUNTIL &RETCODE NE 0
   &GOSUB .PROCESS
   &DOEND
   .
.INITIALIZE
   -* 
   -* Initialization logic
   -*
   &RETSUB
.PROCESS
   -* 
   -* Processing logic
   -*
   &IF &REQUEST = EXIT &THEN +
   &RETSUB 4
   &RETSUB 0
   &PANEL CMDENTRY
   &GOSUB .P$&COMMAND .PEND
   &RETSUB
.P$DISPLAY
   -* 
   -* Display logic
   -*  
   &RETSUB
.P$LIST
   -* 
   -* List logic
   -* 
   &RETSUB
.PEND

Notes:

More information:

&CONTROL

&DO

&DOUNTIL

&LOOPCTL

&DOWHILE