CALLDBPROC
dbproc
ddm-name
|
|||||||||||||
M
|
|||||||||||||
[USING ]
|
parameter |
AD=
|
O
|
||||||||||
A
|
|||||||||||||
[RESULT SETS
result-set]
|
|||||||||||||
[GIVING
sqlcode]
|
This document covers the following topics:
For an explanation of the symbols used in the syntax diagram, see Syntax Symbols.
Belongs to Function Group: Database Access and Update
The CALLDBPROC
statement is used to invoke a stored
procedure of the SQL database system to which Natural is connected.
The stored procedure can be either a Natural subprogram (only available when executed from Db2 for z/OS) or a program written in another programming language.
In addition to the passing of parameters between the invoking object
and the stored procedure, CALLDBPROC
supports "result
sets"; these make it possible to return a larger amount of data from the
stored procedure to the invoking object than would be possible via
parameters.
The result sets are "temporary result tables" which are
created by the stored procedure and which can be read and processed by the
invoking object via a READ
RESULT SET
statement.
Note:
In general, the invoking of a stored procedure could be compared
with the invoking of a Natural subprogram: when the CALLDBPROC
statement is executed, control is passed to the stored procedure; after
processing of the stored procedure, control is returned to the invoking object
and processing continues with the statement following the
CALLDBPROC
statement.
Syntax Element | Description | |
---|---|---|
dbproc
|
Stored Procedure to be
Invoked:
As The name must adhere to the rules for stored procedure names of the target database system. If the stored procedure is a Natural subprogram, the actual procedure name must not be longer than 8 characters. |
|
ddm-name
|
Name of a Natural Data Definition Module:
The name of a DDM must be specified to provide the
"address" of the database which executes the stored procedure. For
further information, see |
|
[USING]
parameter
|
Parameter(s) to be Passed:
As
See further details on
|
|
AD= |
Attribute Definition:
If |
|
AD=O |
Non-modifiable, see session parameter
(Corresponding procedure notation in Db2 for z/OS:
|
|
AD=M |
Modifiable, see session parameter
(Corresponding procedure notation in Db2 for z/OS:
|
|
AD=A |
For input only, see session parameter
(Corresponding procedure notation in Db2 for z/OS:
|
|
If
parameter
is a constant, AD cannot be explicitly specified. For
constants, AD=O always applies.
|
||
RESULT SETS result-set
|
Field for Result-Set Locator Variable:
As A result set has to be a variable of format/length I4. The value of a result set variable is merely a number
which identifies the result set and which can be referenced in a subsequent
The sequence of the
The contents of the result sets can be processed by a
subsequent If no result set is returned, the corresponding result-set
variable will contain Only one result set can be specified. |
|
GIVING
sqlcode
|
GIVING sqlcode
Option:
This option may be used to obtain the SQLCODE of the SQL
If this option is specified and the SQLCODE of the stored
procedure is not The If the |
The following example shows a Natural program that calls the stored
procedure DEMO_PROC
to retrieve all names of table
PERSON
that belong to a given range.
Three parameter fields are passed to DEMO_PROC
: the
first and second parameters pass starting and ending values of the range of
names to the stored procedure, and the third parameter receives a name that
meets the criterion.
In this example, the names are returned in a result set that is
processed using the READ RESULT
SET
statement.
DEFINE DATA LOCAL 1 PERSON VIEW OF DEMO-PERSON 2 PERSON_ID 2 LAST_NAME 1 #BEGIN (A2) INIT <'AB'> 1 #END (A2) INIT <'DE'> 1 #RESPONSE (I4) 1 #RESULT (I4) 1 #NAME (A20) END-DEFINE ... CALLDBPROC 'DEMO_PROC' DEMO-PERSON #BEGIN (AD=O) #END (AD=O) #NAME (AD=A) RESULT SETS #RESULT GIVING #RESPONSE READ RESULT SET #RESULT INTO #NAME FROM DEMO-PERSON GIVING #RESPONSE DISPLAY #NAME END-RESULT ... END