The SUBROUTINE statement must be the first statement in an external subroutine.
Format
SUBROUTINE [name] [(var1,var2,var3)] |
Parameter(s)
name |
Name of the subroutine. |
var ... |
Variables to be assigned by the corresponding CALL statement. If var is an array variable, it must be preceded by the MAT keyword. |
Description
An external subroutine is a subroutine which has been compiled and cataloged separately from the programs that call it. It can then be called by any program with the CALL statement. When a RETURN statement is encountered without a corresponding GOSUB, program control returns to the main program. If there is no ending RETURN statement, control does not return to the main program. See CALL Statement for more information.
The SUBROUTINE statement must be the first line in an external subroutine. The name of the subroutine may be supplied, but it is not necessary since the subroutine is addressed by its item-ID.
The variables var must make a one-to-one correspondence with the parameters supplied on the corresponding CALL statement line. Each of the parameters listed in the CALL syntax line are passed into the corresponding variable list on the SUBROUTINE syntax line. Other than their positions on the CALL and SUBROUTINE syntax lines, there is no correspondence between variable names in the calling program and subroutine.
An alternative way of passing variables between programs and subroutines is by using COMMON statements in both program and subroutine. See COMMON Statement for more information.
If an array variable is passed, it must be preceded by the MAT keyword and dimensioned in both the main program and the subroutine. See CALL Statement for information on passing arrays.
Example
The first line of the subroutine ADDTHEM might read:
SUBROUTINE ADDTHEM (X, Y, Z) |
and the corresponding line for calling ADDTHEM might read:
CALL ADDTHEM (A, B, C) |
Variable A is passed to variable X, B is passed to Y, and C is passed to Z. When the subroutine has finished, these values are passed in the opposite direction.
See Also