Try OpenEdge Now
skip to main content
ABL Essentials
Defining Functions : Defining a function : Making a forward declaration for a function : Making a local forward declaration
 
Making a local forward declaration
If you use the FORWARD keyword in the function prototype, then this tells the AVM to expect the actual function implementation later in the same procedure file. This is a simple example of a function that converts temperature measurements in degrees Celsius scale to degrees Fahrenheit:
/* h-ConvTemp1.p -- convert temperatures and demonstrate functions. */
DEFINE VARIABLE dTemp AS DECIMAL NO-UNDO.

FUNCTION CtoF RETURNS DECIMAL (INPUT dCelsius AS DECIMAL) FORWARD.

REPEAT dTemp = 0 TO 100:
  DISPLAY
    dTemp LABEL "Celsius"
    CtoF(dTemp) LABEL "Fahrenheit"
    WITH FRAME f 10 DOWN.
END.

FUNCTION CtoF RETURNS DECIMAL (INPUT dCelsius AS DECIMAL):
  RETURN (dCelsius * 1.8) + 32.
END FUNCTION.
This procedure executes as follows:
1. The procedure makes a forward declaration of the CtoF conversion function, so that it can be used in the procedure before its implementation code is defined.
2. The function is used inside the REPEAT loop in the DISPLAY statement. Notice that it appears where any DECIMAL expression could appear and is treated the same way.
3. There is the actual implementation of the function, which takes the temperature as measured in degrees Celsius as input and returns the equivalent temperature measurement in degrees Fahrenheit.
The following figure shows the first page of output from the h-ConvTemp1.p procedure.
Figure 42. Result of the ConvTemp.p procedure
You could leave the parameter list out of the function implementation itself, but it is good form to leave it in.