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.

Chapter 3: RDBMS Stored Procedure Details<br />

Retrieving result sets using proc-text-buffer<br />

The proc–text–buffer technique offers one approach to access results returned<br />

from a data source. The following is the partial syntax <strong>for</strong> the DEFINE BUFFER statement<br />

that you use to create a buffer with the same characteristics of the proc–text–buffer:<br />

Syntax<br />

DEFINE BUFFER buffer-name FOR proc-text-buffer<br />

For a complete description, see the reference entry that discusses the DEFINE<br />

BUFFER statement in <strong>OpenEdge</strong> Development: ABL Reference.<br />

Technique to use proc-text-buffer<br />

Example 6 shows the results of the first ABL stored procedure, pcust, which is<br />

Example 3 as presented earlier in this section.<br />

/* pcust stored procedure */<br />

DEFINE BUFFER cust-state-join-buffer FOR proc-text-buffer.<br />

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

FOR EACH cust-state-join-buffer:<br />

DISPLAY cust-state-join-buffer.<br />

END.<br />

CLOSE STORED-PROC pcust.<br />

DISPLAY pcust.orders pcust.states.<br />

Example 6: pcust stored procedure<br />

The <strong>OpenEdge</strong>-defined buffer, proc–text–buffer, has one character field named<br />

proc–text. The buffer accepts the returned database results, converts them to<br />

CHARACTER data type, and concatenates them into one string.<br />

Example 7 illustrates returning database results into the proc–text-buffer and<br />

converting the results to the INTEGER data type.<br />

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

DEFINE VARIABLE iMax as INTEGER NO-UNDO.<br />

RUN STORED-PROC send-sql-statement handle1 = PROC-HANDLE<br />

("SELECT max (cust_num) FROM customer").<br />

FOR EACH proc-text-buffer:<br />

iMax = INTEGER(SUBSTRING(proc-text, 1, 3)).<br />

DISPLAY iMax.<br />

END.<br />

CLOSE STORED-PROC send-sql-statement WHERE PROC-HANDLE = handle1.<br />

Example 7: Returning database results into the proc-text-buffer and results<br />

conversion<br />

The <strong>Data</strong><strong>Server</strong> passes the <strong>SQL</strong> statement directly to the MS <strong>SQL</strong> data source. The<br />

ABL does not process it, so errors occur only at run time and not when you compile a<br />

procedure.<br />

136 <strong>OpenEdge</strong> <strong>Data</strong> <strong>Management</strong>: <strong>Data</strong><strong>Server</strong> <strong>for</strong> <strong>Microsoft</strong> <strong>SQL</strong> <strong>Server</strong>

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

Saved successfully!

Ooh no, something went wrong!