Purpose
Defines the start of a procedure block and specifies the parameters of the procedure, if any.
Syntax
name:PROCEDURE[(parameter-list][RETURNS(t)][EXTERNAL|INTERNAL]
[RECURSIVE][ORDER|REORDER][REDUCIBLE|IRREDUCIBLE]
[OPTIONS(options-list)];
Note:
Abbreviation(s):
- PROC for PROCEDURE
- EXT for EXTERNAL
- INT for INTERNAL
- RED for REDUCIBLE
- IRRED for IRREDUCIBLE
Parameters
-
parameter-list
- One or more parameters, separated by commas, which are expected by the procedure when it is activated. Each parameter specifies the name of a variable declared in the procedure headed by the PROCEDURE statement.
-
t
- A list of data type attributes.
-
options-list
- May be MAIN or VARIABLE.
Options may be specified in any order.
Example
P: PROCEDURE(A,B) RETURNS(FIXED BINARY(15));
DECLARE(A,B) FLOAT;
DECLARE C FIXED BINARY(15);
.
.
.
RETURN ©);
END P;
Q:PROCEDURE(X) RECURSIVE;
DECLARE X CHARACTER(*);
.
.
.
CALL Q('HELLO');
END Q;
Description
The PROCEDURE statement defines the start of a procedure block and specifies the parameters of the procedure, if any. If the procedure is invoked as a function, the PROCEDURE statement also specifies the data type attributes of the value that the function returns to its point of invocation. Execution of a PROCEDURE statement as a consequence of the normal flow of control from the previous statement has no effect and execution resumes with the statement following the procedure's END statement.
The PROCEDURE statement must have a label prefix that declares the name of the procedure. The label declares the primary entry point. That declaration is established in the block that contains the PROCEDURE statement, and consequently makes the name known in that block and in all contained blocks. The procedure's END statement may contain the name of the procedure so that it can be easily identified as the closing END statement. (See the section END Statement.)
Each name in the parameter-list must be declared within the procedure, must not be a member of a structure, and must not be declared with a storage class attribute.
Every call to a procedure not declared with the OPTIONS(VARIABLE) attribute must be made with an argument list containing the same number of arguments as there are parameters in the parameter list, and each argument must be capable of being passed either by reference or by value to its corresponding parameter.
If a RETURNS option is not specified, the procedure must always be called by a CALL statement, and it must not contain any RETURN statements that specify a return value.
If a RETURNS option is specified, t must be a set of data type attributes that specify a scalar value. All values returned by the procedure are converted to this data type prior to being returned as the function value of the procedure. All RETURN statements must specify a return value and the procedure must not execute its own END statement. All calls to the procedure must result from the evaluation of a function reference.
Only one of EXTERNAL or INTERNAL may be specified and only on top-level procedures, that is, those procedures that are not contained within the scope of any other procedure. If EXTERNAL is given, the procedure will be external to the current file being compiled and can be called by other separately compiled procedures. This is the default. If INTERNAL is given, the procedure can only be called by other procedures within the current compilation. Its name is not made available outside this file.
OPTIONS(MAIN) explicitly defines the routine where execution of the program begins. Only one OPTIONS(MAIN) statement is allowed within a program. In a linked executable program, one and only one procedure must be so identified as the main procedure. See the section Main Procedure in the chapter Language Concepts in your Open PL/I User's Guide.
ORDER and REORDER are options sometimes used for optimization in IBM mainframe PL/I programs. Similarly, REDUCIBLE and IRREDUCIBLE are attributes sometimes used by IBM mainframe PL/I programs. None of these are needed by Open PL/I. These options are simply parsed and otherwise ignored by Open PL/I.
The COBOL NOMAP [map-list] option
The FORTRAN NOMAPIN [map-list] option
The TASK NOMAPOUT [map-list] option
The NOEXECOPS option
The OPTION(BYTEADDR) option can be used to ensure the passing of byte addresses, even for items allocated on a bit boundary. When this option is not specified, Open PL/I passes bit addresses for unaligned bit strings. When this option is specified, Open PL/I passes just the address of the first byte of unaligned bit strings.
The word RECURSIVE may be supplied for purposes of documentation. All Open PL/I procedures are capable of recursive use, provided they follow standard recursive programming requirements, such as not using STATIC data.
Procedures may contain other procedures and BEGIN blocks, as well as any other statements.