隐式提交和显式提交(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 MCP 服务器安装配置最佳实践

《MySQLMCP服务器安装配置最佳实践》本文介绍MySQLMCP服务器的安装配置方法,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下... 目录mysql MCP 服务器安装配置指南简介功能特点安装方法数据库配置使用MCP Inspector进行调试开发指

mysql中insert into的基本用法和一些示例

《mysql中insertinto的基本用法和一些示例》INSERTINTO用于向MySQL表插入新行,支持单行/多行及部分列插入,下面给大家介绍mysql中insertinto的基本用法和一些示例... 目录基本语法插入单行数据插入多行数据插入部分列的数据插入默认值注意事项在mysql中,INSERT I

一文详解MySQL如何设置自动备份任务

《一文详解MySQL如何设置自动备份任务》设置自动备份任务可以确保你的数据库定期备份,防止数据丢失,下面我们就来详细介绍一下如何使用Bash脚本和Cron任务在Linux系统上设置MySQL数据库的自... 目录1. 编写备份脚本1.1 创建并编辑备份脚本1.2 给予脚本执行权限2. 设置 Cron 任务2

SQL Server修改数据库名及物理数据文件名操作步骤

《SQLServer修改数据库名及物理数据文件名操作步骤》在SQLServer中重命名数据库是一个常见的操作,但需要确保用户具有足够的权限来执行此操作,:本文主要介绍SQLServer修改数据... 目录一、背景介绍二、操作步骤2.1 设置为单用户模式(断开连接)2.2 修改数据库名称2.3 查找逻辑文件名

SQL Server数据库死锁处理超详细攻略

《SQLServer数据库死锁处理超详细攻略》SQLServer作为主流数据库管理系统,在高并发场景下可能面临死锁问题,影响系统性能和稳定性,这篇文章主要给大家介绍了关于SQLServer数据库死... 目录一、引言二、查询 Sqlserver 中造成死锁的 SPID三、用内置函数查询执行信息1. sp_w

canal实现mysql数据同步的详细过程

《canal实现mysql数据同步的详细过程》:本文主要介绍canal实现mysql数据同步的详细过程,本文通过实例图文相结合给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的... 目录1、canal下载2、mysql同步用户创建和授权3、canal admin安装和启动4、canal

SQL中JOIN操作的条件使用总结与实践

《SQL中JOIN操作的条件使用总结与实践》在SQL查询中,JOIN操作是多表关联的核心工具,本文将从原理,场景和最佳实践三个方面总结JOIN条件的使用规则,希望可以帮助开发者精准控制查询逻辑... 目录一、ON与WHERE的本质区别二、场景化条件使用规则三、最佳实践建议1.优先使用ON条件2.WHERE用

MySQL存储过程之循环遍历查询的结果集详解

《MySQL存储过程之循环遍历查询的结果集详解》:本文主要介绍MySQL存储过程之循环遍历查询的结果集,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录前言1. 表结构2. 存储过程3. 关于存储过程的SQL补充总结前言近来碰到这样一个问题:在生产上导入的数据发现

MySQL 衍生表(Derived Tables)的使用

《MySQL衍生表(DerivedTables)的使用》本文主要介绍了MySQL衍生表(DerivedTables)的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学... 目录一、衍生表简介1.1 衍生表基本用法1.2 自定义列名1.3 衍生表的局限在SQL的查询语句select

MySQL 横向衍生表(Lateral Derived Tables)的实现

《MySQL横向衍生表(LateralDerivedTables)的实现》横向衍生表适用于在需要通过子查询获取中间结果集的场景,相对于普通衍生表,横向衍生表可以引用在其之前出现过的表名,本文就来... 目录一、横向衍生表用法示例1.1 用法示例1.2 使用建议前面我们介绍过mysql中的衍生表(From子句