Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

Transactions and rollback in Protheus

Defines the write unit and cancellation flow.

Transactions and rollback in ProtheusAdvPL
01 · OVERVIEW

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.)

03 · PRACTICAL EXAMPLE

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 Nil
Expected result

When 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.

BEST PRACTICES
  • 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.

Related content

REFERENCES
  1. TOTVS. Controle de transações. DisarmTransaction, TTSBREAK e funções auxiliares. Accessed on 2026-10-28.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha