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

2024-03-12 04:52

本文主要是介绍隐式提交和显式提交(Implicit Database Commits and Explicit Database Commits),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

      • 1 Introduction
      • 2 Detail
      • 3 Summary

文章目录

      • 1 Introduction
      • 2 Detail
      • 3 Summary

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 个数据库游标。

这篇关于隐式提交和显式提交(Implicit Database Commits and Explicit Database Commits)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/800191

相关文章

MySQL 中的 JSON 查询案例详解

《MySQL中的JSON查询案例详解》:本文主要介绍MySQL的JSON查询的相关知识,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录mysql 的 jsON 路径格式基本结构路径组件详解特殊语法元素实际示例简单路径复杂路径简写操作符注意MySQL 的 J

Windows 上如果忘记了 MySQL 密码 重置密码的两种方法

《Windows上如果忘记了MySQL密码重置密码的两种方法》:本文主要介绍Windows上如果忘记了MySQL密码重置密码的两种方法,本文通过两种方法结合实例代码给大家介绍的非常详细,感... 目录方法 1:以跳过权限验证模式启动 mysql 并重置密码方法 2:使用 my.ini 文件的临时配置在 Wi

MySQL重复数据处理的七种高效方法

《MySQL重复数据处理的七种高效方法》你是不是也曾遇到过这样的烦恼:明明系统测试时一切正常,上线后却频频出现重复数据,大批量导数据时,总有那么几条不听话的记录导致整个事务莫名回滚,今天,我就跟大家分... 目录1. 重复数据插入问题分析1.1 问题本质1.2 常见场景图2. 基础解决方案:使用异常捕获3.

SQL中redo log 刷⼊磁盘的常见方法

《SQL中redolog刷⼊磁盘的常见方法》本文主要介绍了SQL中redolog刷⼊磁盘的常见方法,将redolog刷入磁盘的方法确保了数据的持久性和一致性,下面就来具体介绍一下,感兴趣的可以了解... 目录Redo Log 刷入磁盘的方法Redo Log 刷入磁盘的过程代码示例(伪代码)在数据库系统中,r

mysql中的group by高级用法

《mysql中的groupby高级用法》MySQL中的GROUPBY是数据聚合分析的核心功能,主要用于将结果集按指定列分组,并结合聚合函数进行统计计算,下面给大家介绍mysql中的groupby用法... 目录一、基本语法与核心功能二、基础用法示例1. 单列分组统计2. 多列组合分组3. 与WHERE结合使

Mysql用户授权(GRANT)语法及示例解读

《Mysql用户授权(GRANT)语法及示例解读》:本文主要介绍Mysql用户授权(GRANT)语法及示例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录mysql用户授权(GRANT)语法授予用户权限语法GRANT语句中的<权限类型>的使用WITH GRANT

Mysql如何解决死锁问题

《Mysql如何解决死锁问题》:本文主要介绍Mysql如何解决死锁问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录【一】mysql中锁分类和加锁情况【1】按锁的粒度分类全局锁表级锁行级锁【2】按锁的模式分类【二】加锁方式的影响因素【三】Mysql的死锁情况【1

SQL BETWEEN 的常见用法小结

《SQLBETWEEN的常见用法小结》BETWEEN操作符是SQL中非常有用的工具,它允许你快速选取某个范围内的值,本文给大家介绍SQLBETWEEN的常见用法,感兴趣的朋友一起看看吧... 在SQL中,BETWEEN是一个操作符,用于选取介于两个值之间的数据。它包含这两个边界值。BETWEEN操作符常用

MySQL索引的优化之LIKE模糊查询功能实现

《MySQL索引的优化之LIKE模糊查询功能实现》:本文主要介绍MySQL索引的优化之LIKE模糊查询功能实现,本文通过示例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录一、前缀匹配优化二、后缀匹配优化三、中间匹配优化四、覆盖索引优化五、减少查询范围六、避免通配符开头七、使用外部搜索引擎八、分

MySql match against工具详细用法

《MySqlmatchagainst工具详细用法》在MySQL中,MATCH……AGAINST是全文索引(Full-Textindex)的查询语法,它允许你对文本进行高效的全文搜素,支持自然语言搜... 目录一、全文索引的基本概念二、创建全文索引三、自然语言搜索四、布尔搜索五、相关性排序六、全文索引的限制七