Prototyped Calls

With a prototyped call, you can call (with the same syntax):
  • Programs that are on the system at run time
  • Exported procedures in other modules or service programs that are bound in the same program or service program
  • Subprocedures in the same module

If the program or procedure is not defined in the same module as the call, a prototype must be included in the definition specifications of the program or procedure making the call. It is used by the compiler to call the program or procedure correctly, and to ensure that the caller passes the correct parameters.

If the procedure is defined in the same module as the call, it is not necessary to explicitly define a prototype. The prototype can be implicitly defined by the compiler using the information specified by the Procedure Interface for the procedure.

When a program or procedure is prototyped, you do not need to know the names of the data items used in the program or procedure; only the number and type of parameters.

Prototypes improve the communication between programs or procedures. Some advantages of using prototyped calls are:
  • The syntax is simplified because no PARM or PLIST operations are required.
  • For some parameters, you can pass literals and expressions.
  • When calling procedures, you do not have to remember whether operational descriptors are required.
  • The compiler helps you pass enough parameters, of the the correct type, format and length, by giving an error at compile time if the call is not correct.
  • The compiler helps you pass parameters with the correct format and length for some types of parameters, by doing a conversion at run time.

Figure 1 shows an example using the prototype ProcName, passing three parameters. The prototype ProcName could refer to either a program or a procedure. It is not important to know this when making the call; this is only important when defining the prototype.

Figure 1. Sample of CALLP operation
 /FREE
 // The following calls ProcName with the 3
 // parameters CharField, 7, and Field2:
      ProcName (CharField: 7: Field2);

 // If you need to specify operation extenders, you must also
 // specify the CALLP operation code:
      CALLP(e) ProcName (CharField: 7: Field2);
 /END-FREE

When calling a procedure in an expression, you should use the procedure name in a manner consistent with the data type of the specified return value. For example, if a procedure is defined to return a numeric, then the call to the procedure within an expression must be where a numeric would be expected.

For more information on calling programs and procedures, and passing parameters, see the appropriate chapter in the Rational Development Studio for i: ILE RPG Programmer's Guide. For more information on defining prototypes and parameters, see Prototypes and Parameters.