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.

Retrieving return codes<br />

Interfacing with RDBMS stored procedures<br />

You can create a stored procedure that provides return code in<strong>for</strong>mation. For example,<br />

it might indicate whether the stored procedure was successful or whether it<br />

encountered an error condition.<br />

Example 4 shows how ABL code runs the stored procedure pcust. It uses the<br />

PROC–STATUS function and the CLOSE STORED–PROC statement to retrieve the return<br />

code and assign the value to the variable stat. The meaning of this return code is<br />

defined by the underlying data source.<br />

/* Return status */<br />

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

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

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

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

IF stat = 0 THEN<br />

DISPLAY “procedure succeeded”.<br />

Example 4: Return status example<br />

Retrieving output parameter values<br />

When you call a stored procedure, you can specify the ordered list of positional<br />

parameters or you can name them individually. To retrieve output parameter values<br />

from a stored procedure, request them with the keyword OUTPUT or INPUT–OUTPUT<br />

when you execute the procedure. When you run a stored procedure in a <strong>Data</strong><strong>Server</strong><br />

application, the parameters are supplied and passed using <strong>OpenEdge</strong> data types.<br />

Example 5, an ABL procedure, uses the second option <strong>for</strong> passing parameters—it<br />

passes them by name with the PARAM option.<br />

/* Parameters by name */<br />

RUN STORED-PROC pcust (PARAM num = 20, OUTPUT PARAM states = 0,<br />

OUTPUT PARAM orders = 0).<br />

CLOSE STORED-PROC pcust.<br />

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

Example 5: Passing parameters by name using the PARAM option<br />

When you use PARAM to specify parameter names, you do not have to specify all<br />

parameters <strong>for</strong> the stored procedure. Instead, you can include only those parameters<br />

you want to use, in any order you choose. If the stored procedure names a default value<br />

<strong>for</strong> the parameter, you do not have to name that parameter at run time. However, you<br />

must explicitly name parameters that do not have defaults or name them when you<br />

want to pass values that are different from the default.<br />

<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> 135

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

Saved successfully!

Ooh no, something went wrong!