Evaluating Whether a Transaction Was Successful

When you close a transaction by issuing a COMMIT or ROLLBACK command, you must determine whether the command was successful. If a COMMIT command is successful, then the transaction it closes has been successfully written to the data source. If a ROLLBACK command is successful, then the transaction it closes has been successfully rolled back.

The system variable FocCurrent provides the return code of the most recently issued COMMIT or ROLLBACK command. By testing the value of FocCurrent immediately following a COMMIT or ROLLBACK command, you can determine if the transaction was successfully committed or rolled back. If the value of FocCurrent is:

FocCurrent is global to a procedure. If you want a given value of FocCurrent to be available in a different procedure, you must explicitly pass it as an argument to that procedure.


Top of page

Example: Evaluating the Success of a Transaction

The following function commits a transaction to a data source. If the transaction is unsuccessful, the application invokes another function that writes to a log and then begins a new transaction. The FocCurrent line evaluates the success of the transaction:

CASE TransferMoney
   UPDATE AcctBalance FROM SourceAccts
   UPDATE AcctBalance FROM TargetAccts
   COMMIT
   IF FocCurrent NE 0 THEN PERFORM BadTransfer
ENDCASE

WebFOCUS