Q. I read your tip about using CALLP with a variable program name. I want to do something similar, but with procedures. I want a program to choose one from among several different possible procedures to run, depending upon the contents of a database field. Is there a way to do this with CALLP?
A. Sort of. The procedure cannot be a variable. Your program will need a prototype for every possible procedure. You’ll also need a prototype to be associated with a procedure pointer. Then use the %PADDR function to assign a storage location to the procedure pointer. Here’s an example:
// Possible procedures to call
D Addcust PR
D 5U 0 Value
D Updcust PR
D 5U 0 Value
D Delcust PR
D 5U 0 Value
// Prototype for generic procedure
D Process PR Extproc(Processptr)
D 5U 0 Value
// Pointer to hold procedure address
D Processptr S * Procptr
D Action S 1 Inz('A')
D Parameter S 5U 0
/Free
Select; // Assign appropriate procedure address to pointer
When Action = 'A';
Processptr = %Paddr(Addcust);
When Action = 'U';
Processptr = %Paddr(Updcust);
When Action = 'D';
Processptr = %Paddr(Delcust);
Endsl;
Process(Parameter); // Call appropriate procedure
/End-free
The prototype for each procedure must be consistent with the prototype associated with the procedure pointer; that is, they must accept the same parameters. But you can include the OPTIONS(*NOPASS) and/or OPTIONS(*OMIT) keywords to make some parameters optional or omissible.