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–28<br />

Example 3–18 shows the basics of using an existing dynamic temp-table with the<br />

TEMP-TABLE-PREPARE() method.<br />

/* Calling a stored procedure, using an existing temp-table with temp table<br />

prepare*/<br />

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

CREATE TEMP-TABLE tt1Hndl.<br />

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

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

ttHndl:TEMP-TABLE-PREPARE(“ordX”).<br />

RUN STORED-PROC send-sql-statement LOAD-RESULT-INTO ttHndl<br />

(“select custNum,name from myDB.customer”).<br />

Example 3–18: Using an existing dynamic temp-table with the<br />

TEMP-TABLE-PREPARE ( ) method<br />

Note the following points as they relate to Example 3–18:<br />

• As a prerequisite <strong>for</strong> creating the code shown, the developer would need to define the<br />

schema <strong>for</strong> the table.<br />

• Once the temp-table schema begins preparation from the clear state, the temp-table must<br />

be defined to the exact specifications <strong>for</strong> the result sets as generated by the RUN<br />

STORED-PROC statement or send-sql- statement. Otherwise, the RUN STORED-PROC will end<br />

in failure. Also, note the TEMP-TABLE-PREPARE must be called at the completion of the<br />

temp-table definition associated with the stored procedure results.<br />

Example 3–19 shows passing the handles of empty dynamic temp-tables to enable a MS <strong>SQL</strong><br />

<strong>Server</strong> <strong>Data</strong><strong>Server</strong> to create schema based on the result-set schema.<br />

/ *Calling a stored procedure, and using the EXTENT phrase to pass handles of<br />

empty temp-tables to enable the MS <strong>SQL</strong> <strong>Data</strong><strong>Server</strong> to create schema holder<br />

definitions based on each temp-table’s result-set schema. */<br />

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

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

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

CREATE TEMP-TABLE ttCustomer.<br />

CREATE TEMP-TABLE ttOrder.<br />

ttHand1e[1] = ttCustomer.<br />

ttHand1e[2] = ttOrder.<br />

RUN STORED-PROC send-sql-statement LOAD-RESULT-INTO ttHandle<br />

(“Select * from customer; select * from order”).<br />

Example 3–19: Calling a stored procedure and using the EXTENT phrase

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

Saved successfully!

Ooh no, something went wrong!