Function and subroutine subprograms
A function or subroutine subprogram is a subprogram that has a FUNCTION or SUBROUTINE statement as its first statement. You can also specify a function in a statement function statement. An external function or subroutine subprogram is a program unit.
Syntax
- subprogram_statement
- See FUNCTION or SUBROUTINE for syntax details
- specification_part
- is a sequence of statements from the statement groups numbered 2 , 4 and 5 in Order of statements and execution sequence
- execution_part
- is a sequence of statements from the statement groups numbered 4 and 6 in Order of statements and execution sequence, and which must begin with a statement from statement group 6
- internal_subprogram_part
- See Internal procedures for details
- end_subprogram_statement
- See END for syntax details on the END statement for functions and subroutines
Rules
An internal subprogram is declared after the CONTAINS statement in the main program, a module subprogram, or an external subprogram, but before the END statement of the host program. The name of an internal subprogram must not be defined in the specification section in the host scoping unit.
An external procedure has global scope with respect to the executable program. In the calling program unit, you can specify the interface to an external procedure in an interface block or you can define the external procedure name with the EXTERNAL attribute.
A subprogram can contain any statement except PROGRAM, BLOCK DATA, MODULE, and SUBMODULE statements. An internal subprogram cannot contain an ENTRY statement or an internal subprogram.