Try OpenEdge Now
skip to main content
DataServer for Microsoft SQL Server
RDBMS Stored Procedure Details : Handling errors : Trapping errors when using Load-Result-Into
 

Trapping errors when using Load-Result-Into

By properly positioning the NO-ERROR in the RUN statement, error information can also be retrieved from attempted SQL execution at the data source when using LOAD-RESULT-INTO.

Trapping errors using LOAD-RESULT-INTO

The following example shows how errors are trapped after LOAD-RESULT-INTO stored procedure execution.
DEFINE VARIABLE hTables AS HANDLE EXTENT 2 NO-UNDO.

DEFINE TEMP-TABLE ttcust
FIELD cust-num AS INTEGER
FIELD NAME AS CHARACTER.

DEFINE TEMP-TABLE ttord
FIELD ord-num AS INTEGER
FIELD ord-date AS DATE.

hTables[1] = TEMP-TABLE ttcust:HANDLE.
hTables[2] = TEMP-TABLE ttord:HANDLE.

RUN STORED-PROC send-sql-statement LOAD-RESULT-INTO hTables NO-ERROR
  ("Select cust_num, name from customer; Select order_num, order_date from    order_; Select * from order_line")./*Loading three result-sets in two                                       temp-tables raises an error*/

IF ERROR-STATUS:ERROR THEN
  MESSAGE ERROR-STATUS:GET-MESSAGE(1) VIEW-AS ALERT-BOX.
ELSE DO:
  MESSAGE "SQL call was successful." VIEW-AS ALERT-BOX.
  FOR EACH ttcust:
    DISP ttcust.cust-num ttcust.name.
  END.
  FOR EACH ttord:
    DISP ttord.ord-num ttord.ord-date.
  END.
  /* CLOSE STORED-PROC not required w/LOAD-RESULT-INTO */
END.