Marks the starting point of an unchained transaction.
exec sql [at connection_name] begin {transaction | tran} [transaction_name] end-exec
The keywords transaction and tran are interchangeable.
The name that you are assigning to this transaction. The name must conform to the rules for Transact-SQL identifiers.
*
* Use explicit transactions to synchronize tables on
* two servers.
*
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 TITLE-ID PIC X(6).
01 NUM-SOLD PIX S9(9) COMP.
EXEC SQL END DECLARE SECTION END-EXEC.
...
EXEC SQL WHENEVER SQLERROR PERFORM ABORT-TRAN END-EXEC.
EXEC SQL CONNECT :UID IDENTIFIED BY :PASS
AT connect1 END-EXEC.
EXEC SQL CONNECT :UID IDENTIFIED BY :PASS
AT connect2 END-EXEC.
PERFORM TRY-UPDATE.
TRY-UPDATE.
EXEC SQL AT connect1 BEGIN TRANSACTION END-EXEC.
EXEC SQL AT connect2 BEGIN TRANSACTION END-EXEC.
EXEC SQL AT connect1 SELECT sum(qty) INTO :NUM-SOLD
FROM salesdetail
WHERE title_id = :TITLE-ID END-EXEC.
EXEC SQL AT connect2 UPDATE current_sales
SET num_sold = :NUM-SOLD
WHERE title_id = :TITLE-ID END-EXEC.
EXEC SQL AT connect2 COMMIT TRANSACTION END-EXEC.
EXEC SQL AT connect1 COMMIT TRANSACTION END-EXEC.
IF SQLCODE <> 0
DISPLAY "OOPS! Should have used 2-phase commit".
ABORT-TRAN.
EXEC SQL WHENEVER SQLERROR CONTINUE END-EXEC.
DISPLAY "Error code is " SQLCODE.
DISPLAY "Error message is " SQLERRMC.
EXEC SQL AT connect2 ROLLBACK TRANSACTION END-EXEC.
EXEC SQL AT connect1 ROLLBACK TRANSACTION END-EXEC.
PERFORM TRY-UPDATE.
This reference page describes aspects of the Transact-SQL begin transaction statement that differ when used with Embedded SQL. See the Adaptive Server Enterprise Reference Manual for more information about begin transaction and Transact-SQL transaction management.
The begin transaction statement is valid only in unchained transaction mode. In chained transaction mode, you cannot explicitly mark the starting point of a transaction.
When nesting transactions, assign a transaction name only to the outermost begin transaction statement and its corresponding commit transaction or rollback transaction statement.
Unless you set the database option ddl in tran, Adaptive Server does not allow the following statements inside an unchained transaction: create database, create table, create index, create view, drop statements, select into table_name, grant, revoke, alter database, alter table, truncate table, update statistics, load database, load transaction, and disk init.
A transaction includes only statements that execute on the connection that is current when the transaction begins.
Remote procedures execute independently of any transaction in which they are included.
commit transaction, commit work, rollback transaction, rollback work