The CALL statement

You can call an SPL routine or an external routine from an SPL routine using the CALL statement. CALL can execute both procedures and functions. If you use CALL to execute a function, add a RETURNING clause and the name of an SPL variable (or variables) that will receive the value (or values) the function returns.

Suppose, for example, that you want the scale_rectangles function to call an external function that calculates the area of the rectangle and then returns the area with the rectangle description, as in the following figure.
Figure 1: Call an external function.
CREATE FUNCTION scale_rectangles( rectid INTEGER,
      scale REAL )
   RETURNING rectangle_t, REAL;

   DEFINE rectv rectangle_t;
   DEFINE a REAL;
   SELECT rect INTO rectv
      FROM rectangles WHERE id = rectid;
   IF ( rectv IS NULL ) THEN
      LET rectv.start = (0.0,0.0);
      LET rectv.length = 1.0;
      LET rectv.width = 1.0;
      LET a = 1.0;
      RETURN rectv, a;
   ELSE
      LET rectv.length = scale * rectv.length;
      LET rectv.width = scale * rectv.width;
      CALL area(rectv.length, rectv.width) RETURNING a;
      RETURN rectv, a;
   END IF;

END FUNCTION;

The SPL function uses a CALL statement that executes the external function area(). The value area() returns is stored in a and returned to the calling routine by the RETURN statement.

In this example, area() is an external function, but you can use CALL in the same manner with an SPL function.