Procedure Pointers

From MidrangeWiki
Jump to: navigation, search

Procedure pointers are a way to give a program a unique level of flexibility in the way logic is invoked.

Basically, it gives you the ability to store a procedure reference in a pointer variable ... and then invoke that procedure in your code.

The following is a basic example of how to use a procedure pointer:

  // 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                 
  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);
  Process(Parameter);     // Call appropriate procedure          

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.

(Portions copied from

This article is a stub. You can help by editing it.