Transactions and rollback in Protheus
Defines the write unit and cancellation flow.
Overview
Official guidance uses BEGIN/END TRANSACTION and prohibits BeginTran/EndTran in the ERP. DisarmTransaction unwinds from the first open level and enters TTSBREAK; follow it with Break or thread termination under the documented contract. Do not open another transaction before unwinding all pending levels. This no-write lab refuses an existing transaction or TTSBREAK; it demonstrates flow rather than proving data rollback. FWInTTSBreak requires a compatible LIB, documented for versions after 08022017. (Sources: refs. 1–1.)
Commented example
#Include "Protheus.ch"
User Function Ed693()
// Isolated lab: do not interfere with a caller-owned transaction.
If InTransact() .Or. FWInTTSBreak()
Return Nil
EndIf
Begin Transaction
// No writes: demonstrate only the documented exit flow.
DisarmTransaction()
Break
End Transaction
ConOut("Flow completed")
Return NilWhen outside a transaction and TTSBREAK, traverses an empty cancelled transaction. There is no data to roll back. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Open transactions near writes. Avoid input/network waits while holding locks. Database rollback cannot undo email or external APIs; plan those effects separately.
- Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.