ProvideX V8.20 > Language Reference > 2. Directives
241
PERFORM Directive
         Call Subprogram, Share Variables
Format
PERFORM subprog$[;entry$][,ERR=stmtref]
Where:
subprog$ Name of the subprogram to execute. String expression.
;entry$
Optional name of starting line label that is entry point in the subprogram.
stmtref
Program line number or label to transfer control to.
Description
The PERFORM directive saves the current program state, then transfers control to a
subprogram. All variables are made common between the initiating program and
the subprogram. When the subprogram terminates, control returns to the initiating
program at the directive following the PERFORM directive.
Note: All variables that are changed or created during execution of the performed
subprogram will be returned to the initiating program.
You can specify an optional entry point in the subprogram. To do this, append a
semicolon and the starting label name (;entry$) to the subprogram name; e.g.,
PERFORM "SUBPROG;STARTING_LABEL". After the subprogram is loaded,
ProvideX internally issues a GOTO directive using the label as a statement reference
and starts execution there. Use this feature to create subprograms to act as "libraries"
(i.e., multiple stand-alone routines, each starting at its own entry point).
The execution of the subprogram is normally terminated with an EXIT, however, the
END or STOP directives may be used in its place.
Subroutine within a Subprogram
PERFORM can also access subroutines externally via entry points in the called
program. In this case, the RETURN statement that is used to terminate the subroutine
in a subprogram will automatically return control to the initiating program. This
feature allows the same chunk of code to be accessed internally (GOSUB) as well as
externally (PERFORM).
See Also
CALL Transfer to Subprogram, p.40,
RUN Transfer and Execute a Program, p.292
END Halt Program Execution, p.112
EXIT Terminate Subprogram and Return, p.123
STOP Halt Program Execution, p.328
GOSUB.. Execute Subroutine, p.140
RETURN Subroutine/Function Return, p.289
Called Procedures, User's Guide.