If you write a super procedure as a library of general-purpose code, it makes sense that in most cases it should be shareable. The use of TARGET-PROCEDURE facilitates this. If the routines in a super procedure always refer back to the TARGET-PROCEDURE, then they always get data values from the procedure they currently support, that is, the procedure they were invoked from. To make sure that stale data is not left over from call to call, the general rule is to have no variables or any other definitions scoped to the super procedure main block. You should place all definitions within each individual internal procedure or function, so that they safely go out of scope when the routine exits.

This also means that you should structure your application so that only one instance of each super procedure starts for a session. The following example uses the simple mechanism of checking existing procedure handles and their filenames to see if the super procedure is already running, as shown in this procedure:

PROCEDURE start-super-proc :
/*---------------------------------------------------------------------
Purpose:    Procedure to start a super proc if it's not already
            running, and to add it as a super proc in any case.
Parameters: Procedure name to make super.
Notes:      NOTE: This presumes that we want only one copy of a
            super procedure running per session, meaning that they
            are stateless (i.e., that every call is independent of
            every other call). This is intended to be the case
            for ours, but may not be true for all super procs.
--------------------------------------------------------------------*/

DEFINE INPUT PARAMETER pcProcName AS CHARACTER NO-UNDO.
DEFINE VARIABLE hProc AS HANDLE NO-UNDO.

hProc = SESSION:FIRST-PROCEDURE.
DO WHILE VALID-HANDLE(hProc) AND hProc:FILE-NAME NE pcProcName:
  hProc = hProc:NEXT-SIBLING.
END.
IF NOT VALID-HANDLE(hProc) THEN
  RUN VALUE(pcProcName) PERSISTENT SET hProc.
THIS-PROCEDURE:ADD-SUPER-PROCEDURE(hProc, SEARCH-TARGET).

RETURN.

END PROCEDURE.