Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Openedge error-handling sub-transaction not rolled back

Status
Not open for further replies.

haezeban

Programmer
Mar 13, 2013
3
0
0
Hi,

I have following code and try to do error-handling. But there is something wrong.

Routine–level throw error.

PROCEDURE Create-Subrecords :
For each db-table1 no-lock :
LABEL1:
For each db-table2 no-lock
on error undo, next LABEL1 :
For each db-table3 no-lock
on error undo, throw:
Create db-table4.
…..

End. /* db-table3 */
Run proc1. (Do some database updates on db-table2)

Catch e as progress.lang.apperror:
Msg = e:Getmessage(1). /* save message for later */
Undo, next LABEL1.
End catch.

End. /* db-table2 */
End. /* db-table1 */
End PROCEDURE.

The problem is that Proc1 returns an error that is catched by the catch statement.
There I want to Undo all the work done in the transaction started by for each db-table2.

So I thought that all db-table4 records (created in a subtransaction started by for each db-table3)
must be deleted. => but that is not the case, if I look in the db after my program is done all new db-table4 records are there.

What I am doing wrong? Because I want to roll-back (on error) everything that is started in LABEL1.

Thanks for help
 
Hi haezeban ,
I think you need to extend the transaction scope. If you use the "TRANSACTION" function, you can test to see if a transaction has been started and/or finished. you will notice (if my test is the sames as yours) that the transaction is scoped to the db-table3 for each loop. So as it starts at the start of that loop, it is finished in that loop and there is no other transactions apart from in the proc1. You can use the "Do Trans:" feature to extend the transaction to cover as many as the for each statements that need to be in the one transaction. For example, and you would have to test your actual code to see where it needs to go, you could put the DO TRANS: as the first part of the "Create-Subrecords" procedure and make sure you end it at the bottom and then an error in any part of this code will cause the whole transaction to be undone.

This article in our knowledge base might help or at least point you to some other resources that might help you:
HTH
Molly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top