Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   SPL Statements >

CALL

Use the CALL statement to execute a user-defined routine (UDR) from within an SPL routine.

Syntax

Read syntax diagramSkip visual syntax diagram>>-CALL--------------------------------------------------------->
 
>--+-procedure--(--+-----------------------+--)-------------------------+-><
   |               | .-,-----------------. |                            |
   |               | V              (1)  | |                            |
   |               '---| Argument |------+-'                            |
   |                                                       .-,--------. |
   |                                                       V          | |
   +-function--(--+-----------------------+--)--RETURNING----data_var-+-+
   |              | .-,-----------------. |                             |
   |              | V              (1)  | |                             |
   |              '---| Argument |------+-'                             |
   '-routine_var--+-------------------------+---------------------------'
                  |            .-,--------. |
                  |            V          | |
                  '-RETURNING----data_var-+-'
 
Notes:
  1. See Arguments

Element Description Restrictions Syntax
data_var Variable to receive the values function returns The data type of data_var must be appropriate for the returned value Identifier
function,
procedure
User-defined function or procedure The function or procedure must exist Database Object Name
routine_var Variable that contains the name of a UDR Must be a character data type that contains the non-NULL name of an existing UDR Identifier

Usage

The CALL statement invokes a UDR. The CALL statement is identical in behavior to the EXECUTE PROCEDURE and EXECUTE FUNCTION statements, but you can only use CALL from within an SPL routine.

You can use CALL in an ESQL/C program or with DB–Access, but only if the statement is in an SPL routine that the program or DB–Access executed.

If you CALL a user-defined function, you must specify a RETURNING clause.

Specifying Arguments

If a CALL statement contains more arguments than the UDR expects, you receive an error.

If CALL specifies fewer arguments than the UDR expects, the arguments are said to be missing. The database server initializes missing arguments to their corresponding default values. (See CREATE PROCEDURE and CREATE FUNCTION.) This initialization occurs before the first executable statement in the body of the UDR. If missing arguments do not have default values, they are initialized to the value of UNDEFINED. An attempt to use any variable of UNDEFINED value results in an error.

In each UDR call, you have the option of specifying parameter names for the arguments you pass to the UDR. Each of the following examples are valid for a UDR that expects character arguments named t, n, and d, in that order:

CALL add_col (t='customer', n = 'newint', d ='integer');
CALL  add_col('customer','newint','integer');

The syntax is described in more detail in Arguments.

Receiving Input from the Called UDR

The RETURNING clause specifies the variable that receives values that a called function returns.

The following example shows two UDR calls:

CREATE PROCEDURE not_much()
   DEFINE i, j, k INT;
   CALL no_args (10,20);
   CALL yes_args (5) RETURNING i, j, k;
END PROCEDURE 

The first routine call (no_args) expects no returned values. The second routine call is to a function (yes_args), which expects three returned values. The not_much() procedure declares three integer variables (i, j, and k) to receive the returned values from yes_args.

Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]