Procedure Interface

If a prototyped program or procedure has call parameters or a return value, then a procedure interface definition must be defined, either in the main source section (for a cycle-main procedure) or in the subprocedure section. If a prototype was specified, the procedure interface definition repeats the prototype information within the definition of a procedure. Otherwise, the procedure interface provides the information that allows the compiler to implicitly define the prototype. The procedure interface is used to declare the entry parameters for the procedure and to ensure that the internal definition of the procedure is consistent with the external definition (the prototype).

The following rules apply to procedure interface definitions.
  • The name of the procedure interface is optional. If specified, it must match the name of the corresponding prototype definition.
  • In a free-form definition, specify DCL-PI to begin a procedure interface definition. In a fixed-form definition, specify PI in the Definition-Type entry (positions 24-25). The procedure-interface definition can be specified anywhere in the definition specifications. In the cycle-main procedure, the procedure interface must be preceded by the prototype that it refers to, if the prototoype is specified. A procedure interface is if the procedure returns a value, or if it has any parameters; otherwise, it is optional.
  • Any parameter definitions must immediately follow the procedure-interface specification.
  • A free-form procedure interface must end with END-PI, either at the end of the DCL-PI statement, or as a separate statement following the parameters.
  • It is not necessary to specify a name for the procedure interface. In a free-form definition, you use *N to indicate that you are not specifying a name.
  • If you specify a name for the procedure interface, it must be the same as the name of the procedure. If it is a procedure interface for a cycle-main procedure, and you specify a name, it must be the same as the name of a prototype that was previously specified.
  • Parameter names must be specified, although they do not have to match the names specified on the prototype.
  • All attributes of the parameters, including data type, length, and dimension, must match exactly those on the corresponding prototype definition.
  • To indicate that a parameter is a data structure, use the LIKEDS keyword to define the parameter with the same subfields as another data structure.
  • The keywords specified on the PI specification and the parameter specifications must match those specified on the prototype, if the prototype is explicitly specified.
  • If a prototype is not specified, the EXTPGM or EXTPROC keyword may be specified for the procedure interface.
Tip:

If a module contains calls to a prototyped program or procedure that is defined in a different module, then there must be a prototype definition for each program and procedure that you want to call. One way of minimizing the required coding is to store shared prototypes in /COPY files.

If you provide prototyped programs or procedures to other users, be sure to provide them with the prototypes (in /COPY files) as well.