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.

Chapter 3: RDBMS Stored Procedure Details<br />

The data type associated with each column follows the mapping rules that exist<br />

between <strong>OpenEdge</strong> and the <strong>for</strong>eign data source’s data types. For more in<strong>for</strong>mation<br />

about data types and default mapping, see Chapter 2, “Initial Programming<br />

Considerations.”<br />

Note: Since a stored procedure can return multiple result sets, the <strong>Data</strong><strong>Server</strong><br />

prepares the temp-table as “result” where is the result-set sequence<br />

number that corresponds to its element position in the temp table handle array,<br />

starting with 1. There<strong>for</strong>e, if there are 3 result sets and 3 clear dynamic<br />

temp-tables are passed, the temp-tables are called result1, result2, and<br />

result3.<br />

Note the following error conditions as they specifically apply to a dynamic temp-table:<br />

• If an error occurs during the schema population or during the prepare of a<br />

temp-table, the <strong>Data</strong><strong>Server</strong> raises an error condition.<br />

• The dynamic temp-table must be either already prepared or clear with no defined<br />

fields in it. If fields have already been added to a dynamic temp-table be<strong>for</strong>e the<br />

RUN STORED-PROC statement is executed and the temp-table is not prepared, the<br />

<strong>Data</strong>Sever raises an error condition due to the invalid state of the temp-table.<br />

Details about a dynamic temp-table in a prepared state<br />

Example 14 shows multiple dynamic temp-tables in a prepared state. The temp tables,<br />

tt1 and tt2, are prepared in the code just be<strong>for</strong>e the RUN STORED-PROC statement is<br />

called and the temp-tables are passed. The temp-table definition is considered<br />

prepared because of the explicit inclusion of each field name and associated data type.<br />

/* example - Multiple dynamic temp-tables in a prepared state*/<br />

DEFINE VARIABLE tt1 AS HANDLE NO-UNDO.<br />

DEFINE VARIABLE tt2 AS HANDLE NO-UNDO.<br />

DEFINE VARIABLE tt-array AS HANDLE NO-UNDO EXTENT 2.<br />

CREATE TEMP-TABLE tt1.<br />

tt1:ADD-NEW-FIELD(“custnum”, “integer”).<br />

tt1:ADD-NEW-FIELD(“name”, “character”).<br />

/*no more fields will be added */<br />

tt1:TEMP-TABLE-PREPARE (“ordx1”).<br />

CREATE TEMP-TABLE tt2.<br />

tt2:ADD-NEW-FIELD(“ordernum”, “integer”).<br />

tt2:ADD-NEW-FIELD(“orderdate”, “date”).<br />

/*no more fields will be added */<br />

tt2:TEMP-TABLE-PREPARE (“ordx2”).<br />

ASSIGN<br />

tt-array[1] = tt1<br />

tt-array[2] = tt2.<br />

RUN STORED-PROC myproc LOAD-RESULT-INTO tt-array (INPUT 10, INPUT “order”).<br />

Example 14: Multiple temp-tables in a prepared state<br />

In the previous dynamic temp-table example, note that the temp-table definitions must<br />

match the result set that the send-sql- statement returns. For example, the number of<br />

fields and the data type of each field in the result must have a corresponding field<br />

146 <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!