First, prototypes are only used by the compiler to define parameters for a CALLP
op code. But the compiler is smart enough (since v7.1) that if the procedure is defined within the same source as the CALLP
, it can get the parameter definitions from the procedure interface. A prototype is not a runtime object, so does not affect the running of a program once it is successfully compiled.
A prototype is really only required if the procedure or program is called by an external program or procedure using CALLP
. But I usually create prototypes for all EXPORT
ed procedures and MAIN
procedures because I will likely want to call them from some other RPGLE program or procedure, and I only use CALLP
these days.
So here are the various scenarios:
- Procedure called by another procedure in the same source - prototype not needed.
- Procedure or program called by another procedure or program (Not RPGLE) - prototype not needed.
- Program called by OPM program - prototype not needed (not recommended)
- Procedure or program called by another procedure or program (Not using CALLP) - prototype not needed (not recommended)
- Procedure or program called by another procedure or program using CALLP - prototype required.
Just to reiterate, If I am defining a procedure in a module, and that procedure is declared with EXPORT, then I always create a prototype. In addition I always declare a prototype for all program main procedures. These prototypes are always defined in a copy book so the same prototypes can be used in any potential calling program or procedure. I only use CALLP
these days to call procedures or programs from RPGLE, and that op code is always implicit.
Procedures that are defined without EXPORT
never require prototypes, so I do not code them.
NOTE: CALL
and CALLB
must always be explicitly included, I don't use either of those any more.