Skip to content

Begin_Transaction

See Also: Transactions and DDOs, Abort_Transaction, End_Transaction, Lock, Unlock, DF_TRANABORT_ONERROR, DF_TRANSACTION_ABORT

Purpose

To explicitly mark the beginning of a database transaction.

Syntax

Begin_Transaction

What It Does

This command is used to mark the beginning of a database transaction. In case of a rollback, the entire transaction is rolled back. A side effect of the Begin_Transaction command is to execute a Lock command.

Example

Begin_Transaction
Reread
Move "Data Access Corporation" To vendor.name
Save vendor
Save invheader
Move FALSE To bTransOK

For iCount From 1 To 3
    Move iCount To invitems.linenumber
    Save invitems
    // if any item is DataFlex, this is a good transaction
    If (invitems.name Contains "DataFlex") 
        Move TRUE To bTransOK
Loop

If bTransOK
    Unlock
Else
    // Only allow the transaction if DataFlex is purchased.
    Abort_Transaction
    // The next line has no effect if the transaction is aborted.
End_Transaction

Notes

  • A database table may only be used in a transaction if transaction processing is enabled. You can set this by modifying the DF_FILE_TRANSACTION attribute. If any table in a set of tables participating in a transaction is not properly set up for transaction processing, transaction control for the application as a whole will fail.

  • Sometimes the programmer does not explicitly set the beginning and end of a transaction. In this case, DataFlex will use the first Lock command to mark the start of a transaction, and the last Unlock to mark the end of a transaction.

  • You do not need to explicitly use Begin_TransactionEnd_Transaction for database operations that are executed and controlled by DataDictionary objects.

  • Table-manipulation commands like Make_File and Zerofile may not be used within a transaction.

  • The Begin_Transaction and End_Transaction commands must be matched within the same scope. The following structure is not legal:

Begin_TransactionIf (bTest) BeginEnd_Transaction
End