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.

Error handling<br />

Error handling<br />

One common data entry error is attempting to add a duplicate record; that is, trying to create a<br />

record using a unique key that already exists in the database. Suppose, <strong>for</strong> example, that a user<br />

tries to add a customer with custnum = 1 (where custnum is a unique key), but a customer<br />

record with this custnum value already exists. The attempt fails and an error is generated.<br />

When this type of error occurs, ABL run time engine tries to resolve it by working back through<br />

the procedure, looking at each block header until the closest block with the error-handling<br />

property is found, and then undoing and retrying the block. (See <strong>OpenEdge</strong> Getting Started:<br />

ABL Essentials <strong>for</strong> more in<strong>for</strong>mation about error handling.) However, because the <strong>Data</strong><strong>Server</strong><br />

is accessing a non-<strong>OpenEdge</strong> data source, duplicate-key errors can not be detected until the end<br />

of a transaction block. There<strong>for</strong>e, if an error occurs in a subtransaction, it is not detected until<br />

the end of the entire transaction block and default error handling must be per<strong>for</strong>med <strong>for</strong> the<br />

entire transaction block.<br />

The following example illustrates <strong>OpenEdge</strong> database and <strong>Data</strong><strong>Server</strong> error handling:<br />

rep-blk:<br />

REPEAT:<br />

PROMPT-FOR customer.custnum. /* User input */<br />

FIND customer USING custnum NO-ERROR.<br />

IF AVAILABLE customer THEN<br />

UPDATE customer.custnum customer.name customer.state. /* User input */<br />

do-blk:<br />

DO ON ERROR UNDO do-blk, RETRY do-blk:<br />

FIND state WHERE st.state EQ customer.state.<br />

DISPLAY state.<br />

SET state. /* User input */<br />

END.<br />

END.<br />

This procedure displays the following screen, in which the user is prompted to enter data into<br />

the custnum field and then the state field:<br />

The<br />

<strong>OpenEdge</strong><br />

database<br />

prompts <strong>for</strong><br />

the state<br />

abbreviation.<br />

Suppose that the user enters an existing state (<strong>for</strong> example, NH) while ABL is processing the DO<br />

block. When this duplicate-key entry occurs <strong>for</strong> an <strong>OpenEdge</strong> database, ABL returns control to<br />

the DO block, displays a message that the record exists, and reprompts the user <strong>for</strong> a state<br />

abbreviation.<br />

However, with the <strong>Data</strong><strong>Server</strong>, if a duplicate key entry occurs in the DO block, ABL returns<br />

control to the REPEAT block rather than the DO block. As a result, the procedure reprompts the<br />

user <strong>for</strong> a customer number after the inner transaction completes:<br />

2–45

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

Saved successfully!

Ooh no, something went wrong!