Best Practices - Data Transaction Handling

The purpose of this document is to provide best practices for data transaction handling.

Main principles

Managing database transactions requires that you know the main principles associated with this function in the SAFE X3 engine. The main principles are as follows:

Main consequences on the Sage X3 code

Example

# Example of a transaction on a table (ACCOUNT)Subprog CREDIT_DEBIT(ACCOUNT1,ACCOUNT2,AMOUNT,RET_STATUS,RET_MESSAGE)Value Char ACCOUNT1, ACCOUNT2Value Integer AMOUNTVariable Integer RET_STATUSVariable Char RET_MESSAGE()Local Integer TRANS_OPENLocal Char ACCOUNT_CODELocal File ACCOUNT [ACCOUNT]# Open a transaction if not openedIf adxlog=0TRANS_OPEN=0Trbegin [ACCOUNT]Endif# Perform a credit / debit movement# CODE is a unique code so adxuprec can only return 0 or 1Update [ACCOUNT] Where CODE=ACCOUNT1 With [ACCOUNT]BALANCE-AMOUNTIf adxuprec=1Update [ACCOUNT] Where CODE=ACCOUNT2 With [ACCOUNT]BALANCE+AMOUNTElseACCOUNT_CODE=ACCOUNT1EndifIf adxuprec=0ACCOUNT_CODE+=string(ACCOUNT_CODE="",ACCOUNT2) : # Contains the first account not foundRET_STATUS=[V]CST_AERRORRET_MESSAGE="Account"-ACCOUNT_CODE-"not found"If TRANS_OPEN=0RollbackEndifElseRaz RET_MESSAGERET_STATUS=[V]CST_AOKIf TRANS_OPEN=0CommitEndifEndifEnd