Indicates if an explicit transaction is in progress.



Return Value

"1" ($True), or "0" ($False). Can be reset by an application program.


$InTransaction acts as a flag, indicating if the software is currently processing an explicit transaction.

$InTransaction is set to "1" ($True) if a TRANSACTION (or BEGIN WORK) command has started an explicit transaction. It is set to "0" ($False) when an ENDTRANSACTION or QUITTRANSACTION (or COMMIT WORK or ROLLBACK WORK) command has closed the explicit transaction in progress.

The variable is unaffected by deadlock or implicit transactions.


on deadlock
 if $intransaction = $true
  goto RetryAdd
  goto previous
... other commands ...
  ... commands in the transaction ...

In the above example, when a deadlock occurs, $InTransaction determines the course of action that the exception handler takes: restart the explicit transaction (when true) or retry the command that caused the deadlock (when false).

procedure UpdateCode (NewCode) local (DoEndTrans)
 if $intransaction = $false
  let DoEndTrans = $true
 ... other commands ...
 if DoEndTrans = $true

In the above example, $InTransaction starts an explicit transaction if one is not already in progress.


Related Topics