PreviousNextIndex

RUN STORED-PROCEDURE statement

Runs a non-ABL stored procedure or allows you to send SQL to an SQL-based data source using an OpenEdge DataServer.

Syntax

RUN STORED-PROCEDURE procedure 
  [ integer-field = PROC-HANDLE ] 
  [ NO-ERROR ] 
  [ ( parameter [ , parameter ] ... ) ] 

procedure
integer-field = PROC-HANDLE
NO-ERROR
parameter
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 an ODBC-compliant data source.

DEFINE VARIABLE intvar AS INTEGER NO-UNDO. 
RUN STORED-PROCEDURE pcust intvar = PROC-HANDLE  
  (10, OUTPUT 0, OUTPUT 0) NO-ERROR. 
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 of the RUN STORED-PROCEDURE statement 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 an ODBC-compliant data source:

DEFINE VAR handle1 AS INTEGER. 
RUN STORED-PROC 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-PROC send-sql-statement WHERE PROC-HANDLE = handle1. 

This code 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-PROC 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-PROC send-sql-statement WHERE PROC-HANDLE = h1. 

Notes
See also

CLOSE STORED-PROCEDURE statement, PROC-HANDLE function, PROC-STATUS function


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex