隐式提交和显式提交(Implicit Database Commits and Explicit Database Commits)

1 Introduction

A database commit closes all opened database cursors. It is particularly important that database commits are not triggered (in one of the ways listed here) in SELECT loops and after the statement OPEN CURSOR.

2 Detail

Implicit Database Commits

The implicit database commits in an AS ABAP are caused by the fact that an AS ABAP uses its own work processes to connect to the database system. A work process can only ever execute a single database LUW but cannot interfere with the database LUWs belonging to other work processes. Since an ABAP program can be executed by different work processes during its runtime, the database LUW for the current work process must be completed each time an action takes place that leads to a change of work process. As a result, a database commit is performed implicitly in the following situation:

Completion of a dialog step

The program waits for a user action and does not occupy a work process during this time. The next free work process is assigned to the program in the next dialog step.
Calling a function module in a synchronous or asynchronous remote function call

The current work process passes control to a different work process or system. An exception to this are updates. When updates are running, sRFC and aRFC do not cause work processes to be switched or database commits to be executed.
Completion of a function module called in a separate work process using a synchronous remote function call.

Usually, a new work process is allocated to the call program. If a new sRFC follows quickly enough, and enough free work processes exist, the work process sRFC continues to be used, but an implicit database commit is performed regardless.
Execution of the statement RECEIVE in a callback routine specified in an asynchronous RFC

To receive data from the other application server, the current work process must be interrupted before the callback routine is executed A database commit is performed, except during the update.
HTTP/HTTPS/SMTP communication executed using Internet Communication Framework

A database commit is executed before each response is sent in an ICF server program or ICF client program. An exception to this are updates. This behavior applies regardless of whether the communication is stateless or stateful.
Receiving messages from ABAP messaging channels

A database commit is executed while the methods START_MESSAGE_DELIVERY and STOP_MESSAGE_DELIVERY of a consumer object are being executed.
WebSocket or TCP Communication Using ABAP Push Channels

Each time a message is sent and each time APC processing is exited, a database commit is executed. An exception to this are updates. More specifically, the methods BIND_AMC_MESSAGE_CONSUMER and UNBIND_AMC_MESSAGE_CONSUMER (for binding an ABAP messaging channel) produce a database commit.
Current work process interrupted using the statement WAIT UP TO, WAIT FOR ASYNCHRONOUS TASKS, WAIT FOR MESSAGING CHANNELS.

After the interruption, the program is allocated the next free work process. An exception to this are updates.
Sending error messages, information messages, and warnings.

These messages interrupt the current dialog step (see above).
The implicit database commit takes place on all currently open database connections.

Note

If (in the case of implicit database commits) a global temporary table filled using Open SQL statements is not emptied by an explicit database commit or database rollback or by the statement DELETE FROM without WHERE condition, the runtime error COMMIT_GTT_ERROR occurs.

在 ABAP 系统中,存在隐式数据库提交(implicit database commits)的情况,这是由于 ABAP 系统使用自己的工作进程(work processes)与数据库系统进行连接。每个工作进程只能执行一个数据库逻辑单元(database LUW),并且不能干扰其他工作进程的数据库 LUWs。由于在程序运行时 ABAP 程序可以由不同的工作进程执行,因此每当发生导致工作进程变化的动作时,当前工作进程的数据库 LUW 必须完成。这会导致在以下情况下隐式执行数据库提交:

对话步骤完成:程序等待用户操作并在此期间不占用工作进程。在下一个对话步骤中,程序会被分配给下一个可用的工作进程。

调用同步或异步远程函数调用中的函数模块:当前工作进程将控制权传递给不同的工作进程或系统。更新操作除外。在更新操作运行时,sRFC 和 aRFC 不会导致工作进程切换或执行数据库提交。

在单独的工作进程中调用的函数模块完成:通常,调用程序会为调用分配一个新的工作进程。如果新的 sRFC 跟随得足够快,并且存在足够的空闲工作进程,那么 sRFC 工作进程会继续使用,但是无论如何都会隐式执行数据库提交。

在异步 RFC 中指定的回调例程中执行语句 RECEIVE:为了从其他应用服务器接收数据,在执行回调例程之前必须中断当前工作进程。执行数据库提交,更新操作除外。

使用 Internet Communication Framework 执行 HTTP/HTTPS/SMTP 通信:在 ICF 服务器程序或 ICF 客户端程序发送每个响应之前都会执行数据库提交。更新操作除外。

从 ABAP 消息通道接收消息:在执行消费者对象的方法 START_MESSAGE_DELIVERY 和 STOP_MESSAGE_DELIVERY 时会执行数据库提交。

使用 ABAP 推送通道进行 WebSocket 或 TCP 通信:每次发送消息和退出 APC 处理时都会执行数据库提交。更新操作除外。

使用语句 WAIT UP TO、WAIT FOR ASYNCHRONOUS TASKS、WAIT FOR MESSAGING CHANNELS 中断当前工作进程:在中断后,程序会被分配给下一个可用的工作进程。更新操作除外。

发送错误消息、信息消息和警告:这些消息会中断当前对话步骤。

在发生隐式数据库提交时,所有当前打开的数据库连接都会执行数据库提交。需要注意的是,如果使用 Open SQL 语句填充的全局临时表没有通过显式数据库提交、数据库回滚或使用 DELETE FROM(无 WHERE 条件)语句清空,将会导致运行时错误 COMMIT_GTT_ERROR 的发生。
Explicit Database Commits

Database commits can be triggered explicitly in ABAP programs in the following ways:

The relevant database-specific Native SQL statement is used.
In ADBC, only the method COMMIT of the class CL_SQL_CONNECTION can be used to do this. In other cases, the database interface does not detect the end of the transaction and might not be able to perform certain actions.
Any COMMIT statement embedded statically between EXEC and ENDEXEC is detected by the database interface and any required actions performed.
Executing the Open SQL statement COMMIT CONNECTION. The database commit takes place on the specified database connection.
Calling the function module DB_COMMIT. This function module encapsulates the corresponding Native SQL statement. By default, the database commit is triggered on the connection currently open for EXEC SQL. The commit is triggered explicitly on the standard connection by passing the value of abap_true to the input parameter IV_DEFAULT. The function module DB_COMMIT raises the event DB_TRANSACTION_FINISHED of the class CL_DBI_TRANSACTION_STATE, which is handled by the application log framework.
Executing the Open SQL statement COMMIT WORK. The database commit takes place on all currently open database connections. The statement COMMIT WORK also closes the current SAP LUW and performs the associated actions.
COMMITs are not allowed in AMDP methods.

Notes

A simple database commit in an ABAP program is generally done using the statement COMMIT CONNECTION (the standard connection can be specified here using default). The database LUW can be monitored by the application log by using the function module DB_COMMIT. Apart from the database commit itself, using the statement COMMIT WORK also has certain other consequences with respect to the SAP LUW.
All the methods specified here for explicit database commits empty global temporary tables and prevent the runtime error COMMIT_GTT_ERROR in the case of implicit database commits.

在 ABAP 程序中,可以通过以下方式明确触发数据库提交:

使用相关数据库特定的 Native SQL 语句。
在 ADBC 中,只能使用类 CL_SQL_CONNECTION 的方法 COMMIT 来执行数据库提交。在其他情况下,数据库接口无法检测事务的结束,可能无法执行某些操作。
任何嵌入在 EXEC 和 ENDEXEC 之间的 COMMIT 语句都会被数据库接口检测到,并执行任何必要的操作。
执行 Open SQL 语句 COMMIT CONNECTION。数据库提交将在指定的数据库连接上执行。
调用函数模块 DB_COMMIT。该函数模块封装了相应的 Native SQL 语句。默认情况下,数据库提交在当前用于 EXEC SQL 的连接上触发。通过向输入参数 IV_DEFAULT 传递 abap_true 的值,可以在标准连接上显式触发提交。函数模块 DB_COMMIT 会触发类 CL_DBI_TRANSACTION_STATE 的事件 DB_TRANSACTION_FINISHED,该事件由应用程序日志框架处理。
执行 Open SQL 语句 COMMIT WORK。数据库提交将在所有当前打开的数据库连接上执行。COMMIT WORK 语句还会关闭当前的 SAP LUW 并执行相关操作。
在 AMDP 方法中不允许使用 COMMIT。
注:

在 ABAP 程序中,一般通过使用 COMMIT CONNECTION 语句(可以在这里使用默认的标准连接)来执行简单的数据库提交。可以通过函数模块 DB_COMMIT 监视数据库 LUW。除了数据库提交本身外,使用 COMMIT WORK 语句还会对 SAP LUW 产生一些其他后果。
所有在此处指定的明确数据库提交方法都会清空全局临时表,并防止在隐式数据库提交情况下出现运行时错误 COMMIT_GTT_ERROR。

3 Summary

database cursor

Pointer to the results set of a database selection. The database cursor is always assigned to a line of the results set. In Open SQL, cursor handling is implicit, except for the statements OPEN CURSOR, FETCH, and CLOSE CURSOR. A program can open a maximum of 17 database cursors simultaneously using the Open SQL interface.

数据库游标(database cursor)是指向数据库查询结果集的指针。数据库游标始终指向结果集的一行数据。在 Open SQL 中,游标处理是隐式的,除非使用 OPEN CURSOR、FETCH 和 CLOSE CURSOR 等语句。使用 Open SQL 接口,一个程序最多可以同时打开 17 个数据库游标。

  • 24
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值