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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

RDBMS Stored Procedure Details<br />

3–20<br />

Example 3–11 accesses the stored procedure pcust twice; procedure handles (through the<br />

PROC–HANDLE function) identify the different results from your data source.<br />

/* Procedure handles */<br />

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

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

RUN STORED-PROCEDURE pcust handle1 = PROC-HANDLE (20, output 0, output 0).<br />

RUN STORED-PROCEDURE pcust handle2 = PROC-HANDLE (20, output 0, output 0).<br />

FOR EACH pcust_orders WHERE PROC-HANDLE = handle1:<br />

DISPLAY pcust_orders.<br />

END.<br />

FOR EACH pcust_states WHERE PROC-HANDLE = handle1:<br />

DISPLAY pcust_states.<br />

END.<br />

FOR EACH pcust_orders WHERE PROC-HANDLE = handle2:<br />

DISPLAY pcust_orders.<br />

END.<br />

FOR EACH pcust_states WHERE PROC-HANDLE = handle2:<br />

DISPLAY pcust_states.<br />

END.<br />

CLOSE STORED-PROC pcust WHERE PROC-HANDLE = handle1.<br />

CLOSE STORED-PROC pcust WHERE PROC-HANDLE = handle2.<br />

Example 3–11: Procedure handles<br />

The results look the same as in the first two examples. However, because you are running a<br />

stored procedure twice, ABL uses the procedure handles to identify the different instances. If<br />

you have more than one stored procedure open simultaneously in your application, you must<br />

explicitly define procedure handles <strong>for</strong> each.<br />

Example 3–12 shows how to use standard <strong>OpenEdge</strong> syntax to join the results from a stored<br />

procedure with other tables in the database.<br />

/* Join with procedure results */<br />

RUN STORED-PROC pcust (20, output 0, output 0).<br />

FOR EACH pcust_orders, EACH orderline<br />

WHERE pcust_orders.ordernum EQ orderline.ordernum:<br />

DISPLAY orderline.ordernum orderline.itemnum.<br />

END.<br />

FOR EACH pcust_states:<br />

DISPLAY pcust_states.<br />

END.<br />

CLOSE STORED-PROC pcust.<br />

Example 3–12: Joining stored procedure results with other database tables<br />

Example 3–12 joins the order in<strong>for</strong>mation returned from the stored procedure with the<br />

orderline in<strong>for</strong>mation in the same database.

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

Saved successfully!

Ooh no, something went wrong!