The CREATE PROCEDURE statement for an external procedure names
the procedure, defines the parameters and their attributes, and gives other
information about the procedure that the system uses when it calls the procedure.
Consider the following example:
CREATE PROCEDURE P1
(INOUT PARM1 CHAR(10))
EXTERNAL NAME MYLIB.PROC1
LANGUAGE C
GENERAL WITH NULLS
This CREATE PROCEDURE statement:
- Names the procedure P1
- Defines one parameter which is used both as an input parameter and an
output parameter. The parameter is a character field of length ten. Parameters
can be defined to be type IN, OUT, or INOUT. The parameter type determines
when the values for the parameters get passed to and from the procedure.
- Defines the name of the program which corresponds to the procedure, which
is PROC1 in MYLIB. MYLIB.PROC1 is the program which is called when the procedure
is called on a CALL statement.
- Indicates that the procedure P1 (program MYLIB.PROC1) is written in C.
The language is important since it impacts the types of parameters that can
be passed. It also affects how the parameters are passed to the procedure
(for example, for ILE C procedures, a NUL-terminator is passed on character,
graphic, date, time, and timestamp parameters).
- Defines the CALL type to be GENERAL WITH NULLS. This indicates that the
parameter for the procedure can possibly contain the NULL value, and therefore
will like an additional argument passed to the procedure on the CALL statement.
The additional argument is an array of N short integers, where N is the number
of parameters that are declared in the CREATE PROCEDURE statement. In this
example, the array contains only one element since there is only parameter.
It is important to note that it is not necessary to define a procedure
in order to call it. However, if no procedure definition is found, either
from a prior CREATE PROCEDURE or from a DECLARE PROCEDURE in this program,
certain restrictions and assumptions are made when the procedure is called
on the CALL statement. For example, the NULL indicator argument cannot be
passed.