Prototypes

A prototype is a definition of the call interface. It includes the following information:

A prototype may be explicitly or implicitly defined. If the procedure is called from a different RPG module, the prototype must be explicitly specified in both the calling module and the module that defines the procedure. If the procedure is only called within the same module, the prototype may be explicitly defined, or it may be omitted. If the prototype is omitted, the compiler will implicitly define it from the procedure interface.

For modules that call a procedure that is defined in a different module, a prototype must be included in the definition specifications of the program or procedure that makes the call. The prototype is used by the compiler to call the program or procedure correctly, and to ensure that the caller passes the correct parameters.

The following rules apply to prototype definitions.

For information on these keywords, see Definition-Specification Keywords. Figure 67 shows a prototype for a subprocedure CVTCHR that takes a numeric input parameter and returns a character string. Note that there is no name associated with the return value. For this reason, you cannot display its contents when debugging the program.

Figure 67. Prototype for CVTCHR
      * The returned value is the character representation of
      * the input parameter NUM, left-justified and padded on
      * the right with blanks.
     D CVTCHR          PR            31A
     D   NUM                         31P 0   VALUE
      * The following expression shows a call to CVTCHR.  If
      * variable rrn has the value 431, then after this EVAL,
      * variable msg would have the value
      *    'Record 431 was not found.'
     C                   EVAL      msg = 'Record '
     C                                 + %TRIMR(CVTCHR(RRN))
     C                                 + ' was not found '

If you are writing a prototype for an exported subprocedure or for a main procedure, put the prototype in a /COPY file and copy the prototype into the source file for both the callers and the module that defines the procedure. This coding technique provides maximum parameter-checking benefits for both the callers and the procedure itself, since they all use the same prototype.



[ Top of Page | Previous Page | Next Page | Contents | Index ]