RUN STORED-PROCEDURE statement
- Last Updated: July 20, 2021
- 3 minute read
- OpenEdge
- Version 12.2
- Documentation
Runs a non-ABL stored procedure or allows you to send SQL to an SQL-based data source using an OpenEdge DataServer.
Syntax
|
Note that not all options shown can be used simultaneously.
- procedure-name
- The name of the stored procedure that you want to run or the ABL
built-in procedure name
send-sql-statement.Use
send-sql-statementto send an SQL statement to an SQL-based data source. - LOAD-RESULT-INTO handle
- Loads the results using a handle
which points to one or more temp-tables. Note that the handle can be defined as an
EXTENT. This enables you to pass more than one temp-table handle in those instances where SQL statement(s), or named stored procedures, return more than one result set. You can pass an unprepared temp-table (that is, no defined schema) withLOAD-RESULT-INTO. In such cases, the temp-table structure is prepared dynamically. If the temp-table defined by the handle already has a prepared schema, the temp-table structure must match the structure of the result set to avoid data mismatch errors. See the "Data types" section in the "Initial Programming Considerations" of your respective DataServer Guide for data mapping requirements. If multiple result sets are returned, each result set needs its own temp-table mapping. The elements of a temp-table extent should be arranged in the same order that the procedure returns its sets of results.LOAD-RESULT-INTOcarries an implicitCLOSE STORED-PROCEDUREstatement.If handle does not point to a temp-table, a run-time error occurs.
- status = PROC-STATUS
- Assigns an integer value to status containing the return status from the stored procedure. The status is typically a code indicating whether the procedure succeeded or failed and why.
- identifier = PROC-HANDLE
- Assigns a value to identifier, of the appropriate data type (usually INTEGER), that uniquely identifies the stored procedure returning results from the non-OpenEdge database or that uniquely identifies the SQL cursor used to retrieve results from an SQL-based data source, such as a DataServer for Microsoft SQL Server.
- NO-ERROR
- The NO-ERROR option is used to prevent the statement from raising
ERRORand displaying error messages.Note: This option must appear before any run-time parameter list. - parameter
-
A run-time parameter to be passed to the stored procedure. A parameter has the following syntax:
[ INPUT | OUTPUT | INPUT-OUTPUT ] [ PARAM parameter-name = ] expression ) ]INPUT is the default. OUTPUT and INPUT-OUTPUT parameters must be record fields or program variables. For ORACLE, OUTPUT and INPUT-OUTPUT work the same way.
parameter-name is the name of a keyword parameter defined by the stored procedure. If not specified you must supply all the parameters in the correct order and you must precede your assignment statement with the
PARAMkeyword. If you do not supply a required parameter, and no default is specified in the stored procedure, a run-time error occurs.expression is a constant, field name, variable name, or expression. If you use
send-sql-statementfor an SQL-based data source, you must pass only one character expression containing the SQL statement you want the data source to execute.
Examples
This procedure runs the ORACLE stored procedure pcust and
writes the results of the stored procedure into the ABL-supplied buffer,
proc-text-buffer. The same code works for accessing a stored procedure
from a DataServer for Microsoft SQL Server data source.
|
This procedure uses the send-sql-statement option to send SQL to ORACLE. It writes the results of the
stored procedure into the ABL-supplied buffer, proc-text-buffer. The same
code works for sending SQL to a DataServer for Microsoft SQL Server data source:
|
This example shows how to trap errors from the non-OpenEdge RDBMS within a procedure:
|
This example shows how to use the send-sql-statement with the LOAD-RESULT-INTO
option. Note that the temp-table created for tthndl is
unprepared. When tthndl is given to LOAD-RESULT-INTO and the temp-table is unprepared, LOAD-RESULT-INTO prepares the temp-table when results are
returned. Note also that you do not have to specify a CLOSE
STORED-PROCEDURE statement, since it's done implicitly with LOAD-RESULT-INTO.
|
Notes
- The
RUN STORED-PROCEDUREstatement starts a transaction with the same scope as transactions started with theUPDATEstatement. - For more information on using this statement and on using the built-in
procedure names,
send-sql-statement, see the OpenEdge DataServer Guides (Use the Microsoft SQL Data Server and Use the Oracle Data Server).
See also
CLOSE STORED-PROCEDURE statement, NO-ERROR option, PROC-HANDLE function, PROC-STATUS function