13.01.2013 Views

OpenEdge Data Management: DataServer for Microsoft SQL Server

OpenEdge Data Management: DataServer for Microsoft SQL Server

OpenEdge Data Management: DataServer for Microsoft SQL Server

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

RDBMS Stored Procedure Details<br />

Handling errors<br />

3–30<br />

The RUN STORED–PROC statement supports the NO–ERROR option. Example 3–22 shows how to<br />

trap errors within a procedure.<br />

DEFINE VARIABLE ix AS INTEGER NO-UNDO.<br />

RUN STORED-PROC send-sql-statement NO-ERROR<br />

("select count (*) from xxx.customer where name between ’A’ and ’Z’ ").<br />

IF ERROR-STATUS:ERROR THEN DO:<br />

DO ix = 1 TO ERROR-STATUS:NUM-MESSAGES:<br />

MESSAGE "error" ERROR-STATUS:GET-NUMBER(j)<br />

ERROR-STATUS:GET-MESSAGE(j).<br />

END.<br />

END.<br />

CLOSE STORED-PROC send-sql-statement.<br />

Example 3–22: Trapping errors within a procedure<br />

Trapping errors when using Load-Result-Into<br />

By properly positioning the NO-ERROR in the RUN statement, error in<strong>for</strong>mation can also be<br />

retrieved from attempted <strong>SQL</strong> execution at the data source when using LOAD-RESULT-INTO.<br />

Example 3–23 shows how errors are trapped after LOAD-RESULT-INTO stored procedure<br />

execution.<br />

DEFINE VARIABLE hTables AS HANDLE EXTENT 1 NO-UNDO.<br />

RUN STORED-PROC send-sql-statement LOAD-RESULT-INTO hTables NO-ERROR<br />

("Invalid <strong>SQL</strong> Statement").<br />

IF ERROR-STATUS:ERROR THEN<br />

MESSAGE ERROR-STATUS:GET-MESSAGE(1) VIEW-AS ALERT-BOX.<br />

ELSE<br />

MESSAGE "<strong>SQL</strong> call was successful." VIEW-AS ALERT-BOX.<br />

Example 3–23: Trapping errors using LOAD-RESULT-INTO<br />

Error messages related to using the Load-Result-Into<br />

phrase<br />

Note the following situations in which error conditions related to the use of LOAD-RESULT-INTO<br />

are reported:<br />

• The compiler issues an error if you try to specify PROC-HANDLE and LOAD-RESULT-INTO on<br />

the same Run STORED-PROC statement.<br />

• The compiler issues an error if you use PROC-STATUS without specifying the<br />

LOAD-RESULT-INTO function.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!