Calling and Setting a Procedure-Pointer

*> Calling program: 

 program-id. startup.
 working-storage section.
 01 start-point  usage procedure-pointer.
 procedure division.
     set start-point to entry "menu"
     call "controller" using start-point
     display "End of run"
     stop run.

 entry "illegal"
*> Recursive calls invalid without local-storage section.
     stop run.
 end program startup.
*> Called program:

 program-id. controller.
 working-storage section.
 01 next-option  pic x.
 linkage section.
 01 current-proc usage procedure-pointer.
 procedure division using current-proc.
     perform until current-proc = NULL
         call current-proc returning next-option
*>       Note program-id must be called before any entry point
         evaluate next-option
          when "a"    set current-proc to entry "sub1"
          when other  set current-proc to NULL
         end-evaluate
     end-perform.
     exit program.
 end program controller.

 program-id. menu.
 working-storage section.
 01 exit-option  pic x.
 procedure division.
     display "In menu"
     move "a" to exit-option
     exit program returning exit-option.
*>    Note that the maximum size of returned value is 4 bytes

 entry "sub1"
     display "In sub1"
     exit program returning 1.