Bryan's RPG IV Journal
Using CALLP with a Procedure Pointer
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:
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-freeThe 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.
Log of Journal Entries |
|
Use this scrollable blog map to view other journal entries: |
|
| It is your responsibility to ensure procedures, techniques, and code used from this website are accurate and appropriate for your installation. No warranty or support is implied or expressed. |
![]() |
| Privacy and Email Policy |
| AS/400®, eServer, i5/OS, IBM i, Integrated Language Environment®, iSeries, OS/400®, RPG/400®, System i5, VisualAge®, and WebSphere® are trademarks of IBM Corporation. Note: IBM® System i is the latest member of the family of eServer iSeries. This site might refer to System i as System i5, iSeries, or AS/400. |
|
If you are having trouble navigating the menu at the top of this page, you may use the following scrollable site map instead: |
|
|











International visitors: