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.

Figure 1. Instantiate a persistent procedure
The code executes as follows:
  1. MainProc.p RUNs SubProc.p PERSISTENT and saves off its procedure handle in the hProc variable. The main block of SubProc.p defines a variable and then executes the startup code represented by the DO this and DO that statements.
  2. The instantiation of the persistent procedure SubProc.p is complete. It returns control to MainProc.p, passing back through the SET phrase 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, the hProcvariable holds 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.