Replacing *ENTRY PLIST with a Prototype

Q. I am trying to find the /Free replacement for the *ENTRY PLIST. The conversion tool in WDSc doesn’t touch this code. Is it possible to do this in /Free code?

Learn more about prototypes and other ILE RPG features in the “ILE RPG in Easy Bytes” series,” one of several online self-study courses available at my.enskill.com.

A. You’re probably comfortable coding a prototype and procedure interface for a subprocedure. But you can also use PR/PI definitions to replace the *ENTRY PLIST for an RPG IV program When coding a procedure interface for a main procedure (i.e., a program), you must remember a few additional requirements:

  • The prototype for the main procedure must include the Extpgm keyword.
  • The procedure interface must be named (the same as the prototype).
  • The prototype must precede the procedure interface.

You have a choice when naming the prototype and the procedure interface. You can name the PR and PI descriptions to match the name of the module, or you can assign a name of your choosing — perhaps a shop-standard name such as Main. If the name on the PR/PI descriptions doesn’t match the module name, you must specify the module name with the Extpgm keyword (e.g., EXTPGM(‘MYPGM’)).

Here’s a sample *ENTRY PLIST for a program named MYPGM and a pair of sample PR/PI combinations to replace it.

*ENTRY PLIST:

C      *Entry      Plist  
C                  Parm                CpyNbr     5 0 
C                  Parm                AcctID     7

Corresponding PR/PI description:

  // ------------------------------------- Prototypes 
Dcl-pr Mypgm ExtPgm;  
  *N Zoned(5:0);  
  *N Char(7);
End-pr; 
  // ----------------------- Main procedure interface
Dcl-pi Mypgm;  
  CpyNbr Zoned(5:0);  
  AcctID Char(7);
End-pi;

Or:

  // ------------------------------------- Prototypes 
Dcl-pr Main ExtPgm;  
  *N Zoned(5:0);  
  *N Char(7);
End-pr; 
  // ----------------------- Main procedure interface
Dcl-pi Main;  
  CpyNbr Zoned(5:0);  
  AcctID Char(7);
End-pi;

Or:

  // ------------------------------------- Prototypes 
Dcl Main            PR                  ExtPgm('MYPGM')  
D                                5S 0  
D                                7 
  // ----------------------- Main procedure interface 
D Main            PI  
D   CpyNbr                       5S 0  
D   AcctID                       7

You can call this program (MYPGM) from any program, whether or not the calling program prototypes the call. The calling program can even be a CL program or an RPG III program. If the calling RPG IV program also has a prototype for MYPGM, the caller can use a free format call to MYPGM. For example:

  // ------------------------------------- Prototypes 
Dcl-pr Mypgm ExtPgm('MYPGM');  
  *N Zoned(5:0);  
  *N Char(7);
End-pr;
...
Mypgm(Company:Customer);

There are several reasons you might want to switch to using PR/PI descriptions instead of an *ENTRY PLIST. First, the coding is consistent with the coding required for subprocedures, which don’t support *ENTRY PLIST. Second, the free-format replacement specification for C-specs doesn’t support the PLIST or PARM operation; free-format coding renders the *ENTRY PLIST obsolete. Last, you can take advantage of prototyping to better control how parameters are passed by using prototyping keywords such as Const and Options(*NoPass).

Note that you can pass parameters by reference (just as you did with the *ENTRY PLIST) or by read-only reference (Const). You cannot, however, pass parameters by Value to a main procedure, nor does a main procedure support a return value.