HP Business BASIC/XL Reference Manual - HP 3000 MPE/iX Computer Systems - Edition 1 (32715-90001)
3- 35
A subunit can contain any program lines that are valid in a main program,
including variable declaration statements. Except for common variables,
the variables that are defined in a subunit, including formal parame-
ters, are local to that subunit. All variable names in the subunit rep-
resent variables that are distinct from variables with the same names
in other program units. HP Business BASIC/XL allocates space for local
variables when it enters a subunit, and releases that space to memory
when it returns to the calling program.
When HP Business BASIC/XL enters a subunit, it suspends the ON ERROR, ON
END, and ON HALT specifications form the last program unit until control
returns to that program unit. Exceptions to this rule are those "ON"
conditions that specify subunit calls, for example, ON ERROR CALL
Error_Routine.
A subunit is either a subprogram or a user-defined multi-line function.
A subprogram performs a task, but does not return a value to the calling
program unit. A multi-line function returns a value to the calling
program unit unless it is called as a subprogram, in which case the
result is discarded.
Table 3-28 summarizes the differences between subprograms and multi-line
functions.
Table 3-28. Subprograms vs Multi-line Functions
---------------------------------------------------------------------------------------------
|| | |
| Subunit Type | Subprogram | Multi-line Function |
|| | |
---------------------------------------------------------------------------------------------
|| | |
| Begins with | SUBPROGRAM or SUB statement. | DEF FN statement. |
|| | |
---------------------------------------------------------------------------------------------
|| | |
| Ends with | SUBEND statement. | FNEND statement. |
|| | |
---------------------------------------------------------------------------------------------
|| | |
| Returns to | Line following subprogram call. | Line containing function |
| | | call. |
|| | |
---------------------------------------------------------------------------------------------
|| | |
| Returns via | SUBEXIT or SUBEND statement. | RETURN statement. |
|| | |
---------------------------------------------------------------------------------------------
|| | |
| Returns with | No. | Yes. |
| value | | |
|| | |
---------------------------------------------------------------------------------------------
Subprograms
A subprogram is a subunit that performs a task and returns control to the
program unit that called it. It does not return a value to the calling
program unit.