Subroutines

A subroutine is an internal or external procedure that is invoked by a CALL statement.

For the syntax of a subroutine, see Procedures.

The arguments of the CALL statement are associated with the parameters of the invoked procedure. The subroutine is activated, and execution begins. The arguments (zero or more) can be input only, output only, or both.

A subroutine is normally terminated by the RETURN or the END statement. Control is then returned to the invoking block. A subroutine can be abnormally terminated as described in Procedure termination.

A subroutine procedure must meet the following conditions:

  • Not have the RETURNS option on the procedure statement
  • Not be declared as an entry with the RETURNS attribute if it is an external procedure
  • Be invoked using the CALL statement, not a function reference
  • Not return a result value using the RETURN statement

The following examples illustrate the invocation of subroutines that are external to and internal to the invoking block.