Caché SQL Reference
%INTRANSACTION
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Class Reference   
Search:    

Shows transaction state.
Synopsis
%INTRANSACTION
%INTRANS
Arguments
None
Description
The %INTRANSACTION statement sets SQLCODE to indicate the transaction state:
%INTRANSACTION returns SQLCODE=0 while a transaction is in progress. This transaction can be an SQL transaction initiated by START TRANSACTION or SAVEPOINT. It can also be an ObjectScript transaction initiated by TSTART.
Transaction nesting has no effect on %INTRANSACTION. SET TRANSACTION has no effect on %INTRANSACTION.
You can also determine transaction state using $TLEVEL. %INTRANSACTION only indicates whether a transaction is in progress. $TLEVEL indicates both whether a transaction is in progress and the current number of transaction levels.
Examples
The following embedded SQL example shows how %INTRANSACTION sets SQLCODE:
   NEW SQLCODE
   &sql(%INTRANSACTION)
   WRITE "Before %INTRANS SQLCODE=",SQLCODE," TL=",$TLEVEL,!
   &sql(SET TRANSACTION %COMMITMODE EXPLICIT)
   NEW SQLCODE
   &sql(%INTRANSACTION)
   WRITE "SetTran %INTRANS SQLCODE=",SQLCODE," TL=",$TLEVEL,!
  &sql(START TRANSACTION)
   NEW SQLCODE
   &sql(%INTRANSACTION)
   WRITE "StartTran %INTRANS SQLCODE=",SQLCODE," TL=",$TLEVEL,!
   &sql(SAVEPOINT a)
   NEW SQLCODE
   &sql(%INTRANSACTION)
   WRITE "Savepoint %INTRANS SQLCODE=",SQLCODE," TL=",$TLEVEL,!
   &sql(ROLLBACK TO SAVEPOINT a)
   NEW SQLCODE
   &sql(%INTRANSACTION)
   WRITE "Rollback to Savepoint %INTRANS SQLCODE=",SQLCODE," TL=",$TLEVEL,!
   &sql(COMMIT)
   NEW SQLCODE
   &sql(%INTRANSACTION)
   WRITE "After Commit %INTRANS SQLCODE=",SQLCODE," TL=",$TLEVEL
 
See Also