Because functions are so generally useful, you might want to execute a function from many procedures when it is in fact implemented in a single procedure file that your application runs persistent. In this case, you can provide a prototype that specifies the handle variable where the procedure handle of the other procedure is to be found at run time. This is the second option in the prototype syntax:

Syntax

[ MAP [ TO ]actual-name] IN proc-handle

The proc-handle is the name of the handle variable that holds the procedure handle where the function is actually implemented. If the function has a different name in that procedure than in the local procedure, you can provide the MAP TOactual-name phrase to describe this. In that case, actual-name is the function name in the procedure whose handle is proc-handle.

To see an example of the CtoF function separated out in this way:

  1. Create a procedure with just the function definition in it:
    /* h-FuncProc.p -- contains CtoF and possible other useful functions. */
    FUNCTION CtoF RETURNS DECIMAL (INPUT dCelsius AS DECIMAL):
      RETURN (dCelsius * 1.8) + 32.
    END FUNCTION.

    It could also have other internal entries to be used by others that have its procedure handle at run time.

  2. Change the procedure that uses the function to declare it IN hFuncProc, its procedure handle. The code has to run h-FuncProc.p persistent or else access its handle if it's already running. In this case, it also deletes it when it's done:
    /* h-ConvTemp2.p -- convert temperatures and demonstrate functions. */ 
    DEFINE VARIABLE dTemp     AS DECIMAL    NO-UNDO.
    DEFINE VARIABLE hFuncProc AS HANDLE     NO-UNDO.
    
    FUNCTION CtoF RETURNS DECIMAL (INPUT dCelsius AS DECIMAL) IN hFuncProc.
    
    RUN h-FuncProc.p PERSISTENT SET hFuncProc.
    
    REPEAT dTemp = 0 TO 100:
      DISPLAY dTemp LABEL "Celsius"
        CtoF(dTemp) LABEL "Fahrenheit"
        WITH FRAME f 10 DOWN.
    END.
    
    DELETE PROCEDURE hFuncProc.
  3. Run this variant h-ConvTemp2.p, to get the same result as before. This time here is the end of the display, just to confirm that you got the arithmetic right:

An externally defined function such as this one can also reside in an entirely different OpenEdge session, connected to the procedure that uses the function using the application server. In this case, you declare the function in the same way but use the application server-specific ON SERVER phrase on the RUN statement to invoke the function. As with any application server call, you can't pass a buffer as a parameter to such a function.

Making a declaration of a function IN SUPER

The third option in the function prototype is to declare that it is found IN SUPER at run time. This means that the function is implemented in a super procedure of the procedure with the declaration. You learn about super procedures in the Use super procedures in your application section.