Usina BRAdvPL Guide
Sign in
← All topics
COMMANDUnder review

BEGIN TRANSACTION ... END TRANSACTION

BEGIN TRANSACTION // ... END TRANSACTION

Groups writes and controls transaction cancellation.

BEGIN TRANSACTION ... END TRANSACTIONAdvPL
01 · OVERVIEW

Overview

BEGIN TRANSACTION opens a transaction scope; END TRANSACTION closes that scope. Nested transactions are not independent commits. DisarmTransaction disarms through the outer level and places processing in TTSBREAK: use Break to leave the section through its closing scopes before starting another transaction. The example only shows that flow without writes and does not demonstrate data rollback. TOTVS also warns against wrapping standard ExecAuto calls in external transactions without a routine-specific contract. (TOTVS, n.d., refs. 1–2)

02 · SYNTAX

Syntax

BEGIN TRANSACTION
    // ...
END TRANSACTION

Return value

Command without a return; outcome depends on operations and any outer transaction.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"
User Function EdTrans()
    Local lValidated := .F.
    Begin Transaction
        If !lValidated
            // Leave before any write.
            DisarmTransaction()
            Break
        EndIf
    End Transaction
Return Nil
Expected result

Leaves the disarmed path without writing. Actual rollback requires a dedicated test with custom tables and known operations. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Keep transactions short; avoid dialogs while holding locks. Check called routine contracts before adding an outer transaction.
  • 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. TDN. Accessed on 2026-10-26.
  2. TOTVS. FINA460 / ExecAuto: Begin Transaction em fonte customizado. Central de Atendimento. Accessed on 2026-10-26.
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