From the point of view of database programming, a database luw is an inseparable sequence of database operations that ends with a database commit. the database luw is either fully executed by the database system or not at all. once a database luw has been successfully executed, the database will be in a consistent state. if an error occurs within a database luw, all of the database changes since the beginning of the database luw are reversed. this leaves the database in the state it was in before the transaction started. the database changes that occur within a database luw are not actually written to the database until after the database commit. until this happens, you can use a database rollback to reverse the changes. in the SAP system, database commits and rollbacks can be triggered either implicitly or using explicit commands.
Implicit transaction commit (automatic transaction commit) Implicit database commitsA work process can only execute a single database luw. the consequence of this is that a work process must always end a database luw when it finishes its work for a user or an external call. work processes trigger an implicit database commit in the following situations: · when a dialog step is completedcontrol changes from the work process back to the sap gui. · when a function module is called in another work process (RFC ). control passes to the other work process. · when the called function module (RFC) in the other work process ends. control returns to the calling work process. · when
WaitStatement interrupts the work process. Control passes to another work process. · error dialogs (information, warning, or error messages) in dialog steps. Control passes from the work process to the sap gui.
Explicitly commit the transaction explicit database commitsThere are two ways to trigger an explicit database commit in your application programs: · call the function module db_committhe sole task of this function module is to start a database commit. · use the ABAP statement
Commit workThis statement starts a database commit, but also performs other tasks (refer to the keyword documentation
Commit work).
Implicit Transaction rollback (automatic transaction rollback) (implicit database rollbacks)The following cases lead to an implicit database rollback: · runtime error in an application programthis occurs whenever an application program has to terminate because of an unforeseen situation (for example, trying to divide by zero ). · termination messagetermination messages are generated using the ABAP statement
MessageWith the Message Type A or X. In certain cases (updates), they are also generated with message types I, W, and E. These messages end the current application program.
Explicit rollback transaction (explicit database rollbacks)You can trigger a database rollback explicitly using the ABAP statement
Rollback work. This statement starts a database rollback, but also performs other tasks (refer to the keyword documentation
Rollback work). From the above, we can draw up the following list of points at which database luws begin and end.
Start Database Transaction a database luw begins· Each time a dialog step starts (when the dialog step is sent to the work process ). · whenever the previous database luw ends in a database commit. · whenever the previous database luw ends in a database rollback.
End Database Transaction a database luw ends· Each time a database commit occurs. This writes all of the changes to the database. · each time a database rollback occurs. This reverses all of the changes made during the luw.
Database luws and database locksAs well as the database changes made within it, a database luw also consists of database locks. the database system uses locks to ensure that two or more users cannot change the same data simultaneously, since this cocould lead to inconsistent data being written to the database. A database lock can only be active for the duration of a database luw. they are automatically released when the database luw ends. in order to program sap luws, we need a lock mechanic within the R/3 system that allows us to create locks with a longer lifetime (refer to the SAP locking concept ).
Related connection http://blog.csdn.net/CompassButton/archive/2006/12/15/1444415.aspx