Runs a non-ABL stored procedure or allows you to send SQL to an SQL-based data source using an OpenEdge DataServer.
RUN STORED-PROCEDURE procedure-name [[ LOAD-RESULT-INTO handle [ status = PROC-STATUS ]] | [ identifier = PROC-HANDLE]] [ NO-ERROR ] [ ( parameter [ , parameter ] . . . ) ] |
Note that not all options shown can be used simultaneously.
Use send-sql-statement to send an SQL statement to an SQL-based data source.
LOAD-RESULT-INTO carries an implicit CLOSE STORED-PROCEDURE statement.
If handle does not point to a temp-table, a run-time error occurs.
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 PARAM keyword. 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-statement for an SQL-based data source, you must pass only one character expression containing the SQL statement you want the data source to execute.
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.
DEFINE VARIABLE intvar AS INTEGER NO-UNDO. RUN STORED-PROCEDURE pcust intvar = PROC-HANDLE NO-ERROR (10, OUTPUT 0, OUTPUT 0). FOR EACH proc-text-buffer WHERE PROC-HANDLE = intvar: DISPLAY proc-text-buffer. END. IF ERROR-STATUS:ERROR THEN MESSAGE "Stored Procedure failed to run". ELSE CLOSE STORED-PROCEDURE pcust WHERE PROC-HANDLE = intvar. |
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:
DEFINE VAR handle1 AS INTEGER. RUN STORED-PROCEDURE send-sql-statement handle1 = PROC-HANDLE ("SELECT name, cust_num FROM customer"). FOR EACH proc-text-buffer WHERE PROC-HANDLE = handle1: DISPLAY proc-text. END. CLOSE STORED-PROCEDURE send-sql-statement WHERE PROC-HANDLE = handle1. |
This example shows how to trap errors from the non-OpenEdge RDBMS within a procedure:
DEFINE VAR h1 AS INTEGER NO-UNDO. DEFINE VAR jx AS INTEGER NO-UNDO. RUN STORED-PROCEDURE send-sql-statement h1 = PROC-HANDLE NO-ERROR ("select count (*) from xxx.customer where name between 'A' and 'Z' "). IF ERROR-STATUS:ERROR THEN DO jx = 1 TO ERROR-STATUS:NUM-MESSAGES: MESSAGE "error" ERROR-STATUS:GET-NUMBER(jx) ERROR-STATUS:GET-MESSAGE(jx). END. CLOSE STORED-PROCEDURE send-sql-statement WHERE PROC-HANDLE = h1. |
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.