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.

Interfacing with RDBMS stored procedures<br />

The easiest way to create a buffer that accepts data from stored procedures is to use the text of<br />

the <strong>SQL</strong> SELECT statement from the stored procedure. This ensures that you define your data<br />

types correctly and in the correct order. Use a native process such as sp_helptext to view the<br />

stored procedure from a MS <strong>SQL</strong> <strong>Server</strong>, or view procedures in the system tables.<br />

The examples in this section do not use the supplied proc-text-buffer buffer. Instead, they<br />

show how to define <strong>for</strong>matted buffers by creating views in the data source, using the following<br />

syntax:<br />

Syntax<br />

CREATE VIEW _BUFFER_buffer-name<br />

Example 3–8 and Example 3–9 show the views created in your MS <strong>SQL</strong> <strong>Server</strong> data source that<br />

you can use as buffers to store the results from the stored procedure pcust.<br />

CREATE VIEW _BUFFER_pcust_orders AS SELECT customer.cust_num,<br />

customer.name, order_num FROM customer, order_ WHERE 1 = 0<br />

GO<br />

Example 3–8: First view created in your MS <strong>SQL</strong> <strong>Server</strong> data source<br />

CREATE VIEW _BUFFER_pcust_states AS SELECT cust_num, state.state<br />

FROM customer, state WHERE 1 = 0<br />

GO<br />

Example 3–9: Second view created in your MS <strong>SQL</strong> <strong>Server</strong> data source<br />

Example 3–10 shows ABL procedure results of the previous stored procedure pcust as it is<br />

written into the new buffers pcust_orders and pcust_states.<br />

/* Results of the first two example code examples - Typed buffers */<br />

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

FOR EACH pcust_orders:<br />

DISPLAY pcust_orders.<br />

END.<br />

FOR EACH pcust_states:<br />

DISPLAY pcust_states.<br />

END.<br />

CLOSE STORED-PROC pcust.<br />

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

Example 3–10: Result set of pcust - typed buffers<br />

Because two different buffers have been defined, the returned values maintain their data types<br />

instead of being converted to character strings and stored in the <strong>OpenEdge</strong>-defined buffer<br />

proc–text–buffer. You can then use the returned values in calculations without first<br />

converting them back to their original data types. In addition, the two separate buffers make<br />

your output look cleaner, allowing ABL to build a new default frame <strong>for</strong> the two different types<br />

of output. Reading your results into an explicitly defined buffer also allows you to manipulate<br />

the data just as you would manipulate data from an <strong>OpenEdge</strong> database; <strong>for</strong> example, with<br />

Frame phrases and FORM statements.<br />

3–19

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

Saved successfully!

Ooh no, something went wrong!