Adding New Parameters to RPG Programs
July 21, 2004 Hey, Ted
We have an RPG IV program that accepts one parameter. We need to add two more parameters. Our problem is that this program is called from several menus and many programs. Unless you have some trick up your sleeve, adding the new parameters will involve a lot of work outside of regular hours. Can you help?
This is not a difficult situation to handle, Bo. There’s no trick to it, and this is a fundamental technique that everybody should know.
As long as you do not reference a parameter that is not passed to the program, the RPG program will not cancel. You can use RPG IV’s %PARMS built-in function to determine how many parameters are passed to the program on the CALL command.
Add the parameters the end of the parameter list. In this example, I call them PARM2 and PARM3. You’ll use more descriptive names, of course.
C *entry plist C parm parm1 5 C parm parm2 3 0 C parm parm3 10
Define two variables as you’ve defined the new parameters. I’ll call them WORK2 and WORK3.
D work2 s like(parm2) D work3 s like(parm3)
Use the %PARMS function to determine whether each parameter was passed. If a parameter was passed into the program, load its value into the corresponding work variable. If a parameter was not passed into the program, assign a default value to the work variable.
Use the work variables, not the parameters, throughout the program.
Using this technique lets you leave existing calls as they are, as long as the default values for the new parameters are acceptable. You will only need to modify the calls that need to pass other parameter values.
You’re fortunate that the program you must change was written in RPG and not CL. When you call a CL program, you must pass exactly the number of expected parameters. You can work around this problem to an extent by creating commands to run CL programs, but that is a topic for some other day.