关于SAP的事务提交和回滚(LUW)

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 Database Commits
A 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 completed
Control 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 a WAIT statement 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.
显式提交事务Explicit Database Commits
There are two ways to trigger an explicit database commit in your application programs:
·        Call the function module DB_COMMIT
The sole task of this function module is to start a database commit.
·        Use the ABAP statement COMMIT WORK
This statement starts a database commit, but also performs other tasks (refer to the keyword documentation for COMMIT WORK).
隐式事务回滚(自动回滚事务)(Implicit Database Rollbacks)
The following cases lead to an implicit database rollback:
·        Runtime error in an application program
This occurs whenever an application program has to terminate because of an unforeseen situation (for example, trying to divide by zero).
·        Termination message
Termination messages are generated using the ABAP statement MESSAGE with 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 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 for ROLLBACK WORK).
From the above, we can draw up the following list of points at which database LUWs begin and end.
开始数据库事务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.
结束数据库事务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 Locks
As 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 could 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 mechanism within the R/3 System that allows us to create locks with a longer lifetime (refer to The SAP Locking Concept).
 相关连接 http://blog.youkuaiyun.com/CompassButton/archive/2006/12/15/1444415.aspx 
MySQL中的事务是一组原子操作,这些操作要么全部完成,要么全部不完成。如果事务中的任何一个操作失败,则整个事务将被回滚到最初状态。 事务提交回滚是MySQL中非常重要的操作,可以通过以下方式进行实现: 1. 事务提交:当事务中的一组操作全部成功执行后,可以通过执行COMMIT语句来提交事务,使得这些操作的结果永久保存在数据库中。 2. 事务回滚:当事务中的任何一个操作失败或者发生错误时,可以通过执行ROLLBACK语句来回滚事务,使得数据库恢复到事务开始之前的状态。 在MySQL中,可以通过以下方式进行事务操作: 1. 使用START TRANSACTION语句来开始一个新的事务。 2. 在事务中执行多个操作,例如INSERT、UPDATE、DELETE等。 3. 如果事务中的所有操作都成功执行,使用COMMIT语句来提交事务。 4. 如果事务中的任何一个操作失败或者发生错误,使用ROLLBACK语句来回滚事务。 例如,以下是一个MySQL事务的示例: ``` START TRANSACTION; INSERT INTO users (name, email) VALUES ('John Doe', 'john@example.com'); UPDATE accounts SET balance = balance - 100 WHERE user_id = 1; COMMIT; ``` 在上面的示例中,我们首先使用START TRANSACTION语句开始一个新的事务,然后在事务中执行了两个操作:向users表中插入一条新记录,以及更新accounts表中用户1的余额。最后,如果所有操作都成功执行,我们使用COMMIT语句提交事务。如果在执行这些操作的过程中发生了错误,我们可以使用ROLLBACK语句回滚事务
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值