Entry Parameters of ILE RPG, RPG IV Programs

Entry Parameters of A Program

How have you been calling your program given in this tutorial? I guess by using a command similar to "call pgmname". What if you need to pass some arguments in your program. In RPGLE you can specify whether a program should expect some argument(parameter) or not. You do this by specifying the entry parameters in your program. The entry parameters are specified as a parameter list (list of parameters). The name of this parameter list is always *Entry. The syntax to define a parameter list can be understood by the example given below.

DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++
D@Entry           S             10A               
 **                                               
CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result
C     *Entry        PList                         
C                   Parm                    @Entry
 **                                               
C     @Entry        Dsply                         
C                   Return 

To run this program we can use either the positional or the keywords syntax. The simplest way to call the above program is "Call programname 'Parameter'". The program displays the text entered as parameter.


Passing Multiple Parameters to an ILE RPG Program
To pass more than one arguments, we need to just add one more parameter in the
*Entry parameter list. The following example will accept two parameters.

DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++
D@Entry1          S             10A                
D@Entry2          S             10A                
 **                                                
CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result+
C     *Entry        PList                          
C                   Parm                    @Entry1
C                   Parm                    @Entry2
 **                                                
C     @Entry1       Dsply                          
C     @Entry2       Dsply                          
C                   Return                         

To run the above program from command line use the follwing command statement "Call PgmName Parm(parm1 parm2)". If there is only one parameter as was the previous case you can call the program by using positional method. For this just specify the parameter after the program name. e.g
"Call pgmname parm1".

The entery parameters are specified generally in initialization subroutine.

Note:- If we do not pass any parameter to program which expects some entery parameter, the program will end with an error 'Pointer or parameter error (C G D F). Also, the Entry Parameters are never initialized! '.