You define transactions in the PROCEDURE DIVISION to control what changes
are committed to a DBEnvironment and when they are committed.
A transaction consists of all the
SQL commands that are executed between
a BEGIN WORK command and either a COMMIT WORK command or a
ROLLBACK WORK command. When a COMMIT
WORK command is successfully executed, all operations performed
within the transaction are permanent in the
DBEnvironment.
When a ROLLBACK WORK command is executed, none of the changes
remain in the DBEnvironment.
The number and duration of transactions in an application program
depends on such factors a concurrency and data consistency. For detailed
information regarding transaction management, see the .
The commands at 4 and 5 in Figure 3-1 “Sample Program COBEX2 ” start and
end a transaction that consists of a single execution of the
SELECT command in paragraph B100-SELECT-DATA.
The BEGIN WORK command in paragraph A300-BEGIN-TRANSACTION
is optional, but recommended. If you omit a BEGIN WORK command,
ALLBASE/SQL automatically issues a
BEGIN WORK on your behalf before executing the first SQL command that
requires that a transaction be in progress.
The COMMIT WORK command in paragraph
A400-END-TRANSACTION terminates the transaction after each execution
of the SELECT command.
Because the program does no DBEnvironment
updates, this command is used to terminate the transaction even
if an error is encountered. In programs that update data in
a DBEnvironment, a ROLLBACK WORK command could be used to
undo the effects of any database changes that occurred during a
transaction before the error occurred.