Instantiate the persistent procedure
- Last Updated: August 7, 2023
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
What happens when you run a procedure PERSISTENT? You already know that a
procedure has a main block, which has all the code and definitions that are scoped to
the procedure itself. Another way of saying this is that this is everything in the
procedure file that is not in an internal procedure or a trigger. When you run a
procedure PERSISTENT, its main block executes and then returns to the
caller, just as it would without the PERSISTENT keyword. The difference
is that when you run it PERSISTENT, the procedure stays in memory so
that you can run internal procedures in it later on. The following diagram shows how
this works.
- MainProc.p
RUNs SubProc.pPERSISTENTand saves off its procedure handle in thehProcvariable. The main block of SubProc.p defines a variable and then executes the startup code represented by theDO thisandDO thatstatements. - The instantiation of the persistent procedure SubProc.p is
complete. It returns control to MainProc.p, passing back
through the
SETphrase the procedure handle it was given. SubProc.p now is removed from the call stack. At this point, and for the duration of MainProc.p, thehProcvariableholds the procedure handle of the running instance of SubProc.p.
Later you see how you can make use of this handle.
Now that SubProc.p is in memory, MainProc.p (or
any other procedure with access to its handle) can make use of it by running
h-UsefulProc1 and h-UsefulProc2 whenever it needs
to.