Cycle Module

A cycle module has a cycle-main procedure which uses the RPG Program Cycle; the procedure is implicitly specified in the main source section . (See Program Cycle.) You do not need to code anything special to define the main procedure; it consists of everything before the first Procedure specification. The parameters for the cycle-main procedure can be coded using a procedure interface and an optional prototype in the global Definition specifications, or using a *ENTRY PLIST in the cycle-main procedure’s calculations.

The name of the cycle-main procedure must be the same as the name of the module being created. You can either use this name for the prototype and procedure interface, or specify this name in the EXTPROC keyword of the prototype, or of the procedure interface, if the prototype is not specified.

Any procedure interface found in the global definitions is assumed to be the procedure interface for the cycle-main procedure. If a prototype is specified, the name is required for the procedure interface for the cycle-main procedure, and the prototype with the matching name must precede the procedure interface in the source.

In the following example, module CheckFile is created. Its cycle-main procedure has three parameters:

  1. A file name (input)
  2. A library name (input)
  3. An indicator indicating whether the file was found (output)

In this example, the procedure is intended to be called from another module, so a prototype must be specified in a /COPY file.

/COPY file CHECKFILEC with the prototype for the cycle-main procedure:

D CheckFile       PR
D   file                        10a   const
D   library                     10a   const
D   found                        1N

Module CheckFile:

 /COPY CHECKFILEC
D CheckFile       PI
D   file                        10a   const
D   library                     10a   const
D   found                        1N
C   ... code using parameters file, library and found

Using a *ENTRY PLIST, you would define the parameters this way:

D file            S             10a   const
D library         S             10a   const
D found           S              1N
C     *ENTRY        PLIST
C                   PARM                    file
C                   PARM                    library
C                   PARM                    found
C   ... code using parameters file, library and found

You can also use a prototype and procedure interface to define your cycle-main procedure as a program. In this case, you would specify the EXTPGM keyword for the prototype. In this example, the program is intended to be called by other RPG programs, so a prototype must be specified in a /COPY file.

/COPY file CHECKFILEC with the prototype for the program:

 D CheckFile       PR                  extpgm('CHECKFILE')
 D   file                        10a   const
 D   library                     10a   const
 D   found                        1N

In the module source, the procedure interface would be defined the same way.

In the following example, the program is not intended to be called by any other RPG programs, so a prototype is not necessary. In this case, the EXTPGM keyword is specified for the procedure interface. Since a prototype is not specified, a name is not necessary for the procedure interface.

A procedure interface with the EXTPGM keyword:

 F ... file specifications
 D                 PI                  extpgm('CUSTREPORT')
 D   custfile                    10a   const
 D   custlib                     10a   const
  ... code using the custfile and custlib parameters


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