Q. I understand how to prototype a program call, using EXTPGM and naming the program. But I want to allow the user to select an item from a subfile, then have the program use that selection to choose one from among several different possible programs to run. Is there a way to do this?
A. Yes. The EXTPGM value can be a character variable, as well as a literal or constant:
D Mypgm PR Extpgm(Pgmname)
D 5U 0 Const
D 35 Const
D Parm1 S 5U 0
D Parm2 S 35
D Pgmname S 10
Pgmname = 'AR101';
Mypgm(Parm1:Parm2); // Call AR101 (Implied Callp)
Pgmname = 'PR457';
Mypgm(Parm1:Parm2); // Call PR457 (Implied Callp)
The parameter list must be consistent for any of the possible programs to be called; that is, AR101 and PR457 must accept the same parameters. But you can include the OPTIONS(*NOPASS) and/or OPTIONS(*OMIT) keywords to make some parameters optional or omissible.
The called programs (AR101 and PR457) need not be coded with prototypes, even though the calling program will use prototyping and CALLP.