GOSUB
The GOSUB statement transfers processing control to the statement immediately following the referenced label or subroutine. Execution of a subsequent RETURN statement transfers control to the statement following the GOSUB.
••••• GOSUB
••• ••••••••••••••••••••••••••••••
(1)
(2) (3)
(2) Application ID (optional) |
(3) Label or subroutine name |
The GOSUB statement stores the current values of the internal true/false status indicators, clears the values before executing the subroutine, and restores them upon returning from the subroutine. In addition, when implemented, GOSUB will set the next status indicator to the value indicated in the RETURN statement, if any. (Note: when designing subroutines, be sure that no true/false levels are expected upon entering the subroutine.)
The GOSUB statement specifies a label name or subroutine process. The GOSUB statement first tries to locate a corresponding LABEL within the event point being executed. If no such LABEL exists, APPX attempts to locate a subroutine process with that name in the specified application. If the application ID in the GOSUB statement is blank, it is assumed to be the current application.
If the GOSUB reference is to a label within the event point, the application ID should be blank or the current application.
If the reference is to a subroutine process, the following statements are generated automatically at process compile time, at the end of the event point:
END
LABEL (label
from GOSUB statement)
COPY (application
ID and label from GOSUB statement)
RETURN
This allows subroutine processes to be invoked by GOSUB as well as by COPY or SUBR.
The GOSUB statement passes the current PASS list, if any. Refer to the PASS Lists section for details.
If there is no corresponding LABEL and no subroutine process with the name identified in the GOSUB for the referenced application, and if the referenced application is a valid application in System Administration, a non-recoverable error occurs at runtime.
If there is no corresponding LABEL and the application ID refers to a nonexistent application, the statement is ignored.
COPY, END, GOTO, LABEL, PASS, RECEIVE, RETURN, SUBR
*
* On
Account or Regular posting?
*
IF TAR
RECEIPT3 APPLY TYPE NE 1
T GOSUB :REGULAR
POST
F GOSUB :ON
ACCOUNT POST
*
END
*
LABEL :REGULAR
POST
* (perform
regular posting)
RETURN
*
LABEL :ON
ACCOUNT POST
* (perform
on account posting)
RETURN
Notice that, in this example, the subroutine does not use the values of the true/false status indicators established before the GOSUB. Instead, APPX stores the current values of those indicators, executes the subroutine, and then restores the original values upon completion of the subroutine. This allows you to have the use of the full range of true/false values within a subroutine.