隐式提交和显式提交(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的not exists走不走索引

《浅谈mysql的notexists走不走索引》在MySQL中,​NOTEXISTS子句是否使用索引取决于子查询中关联字段是否建立了合适的索引,下面就来介绍一下mysql的notexists走不走索... 在mysql中,​NOT EXISTS子句是否使用索引取决于子查询中关联字段是否建立了合适的索引。以下

Java通过驱动包(jar包)连接MySQL数据库的步骤总结及验证方式

《Java通过驱动包(jar包)连接MySQL数据库的步骤总结及验证方式》本文详细介绍如何使用Java通过JDBC连接MySQL数据库,包括下载驱动、配置Eclipse环境、检测数据库连接等关键步骤,... 目录一、下载驱动包二、放jar包三、检测数据库连接JavaJava 如何使用 JDBC 连接 mys

SQL中如何添加数据(常见方法及示例)

《SQL中如何添加数据(常见方法及示例)》SQL全称为StructuredQueryLanguage,是一种用于管理关系数据库的标准编程语言,下面给大家介绍SQL中如何添加数据,感兴趣的朋友一起看看吧... 目录在mysql中,有多种方法可以添加数据。以下是一些常见的方法及其示例。1. 使用INSERT I

Qt使用QSqlDatabase连接MySQL实现增删改查功能

《Qt使用QSqlDatabase连接MySQL实现增删改查功能》这篇文章主要为大家详细介绍了Qt如何使用QSqlDatabase连接MySQL实现增删改查功能,文中的示例代码讲解详细,感兴趣的小伙伴... 目录一、创建数据表二、连接mysql数据库三、封装成一个完整的轻量级 ORM 风格类3.1 表结构

MySQL 中的 CAST 函数详解及常见用法

《MySQL中的CAST函数详解及常见用法》CAST函数是MySQL中用于数据类型转换的重要函数,它允许你将一个值从一种数据类型转换为另一种数据类型,本文给大家介绍MySQL中的CAST... 目录mysql 中的 CAST 函数详解一、基本语法二、支持的数据类型三、常见用法示例1. 字符串转数字2. 数字

Mysql实现范围分区表(新增、删除、重组、查看)

《Mysql实现范围分区表(新增、删除、重组、查看)》MySQL分区表的四种类型(范围、哈希、列表、键值),主要介绍了范围分区的创建、查询、添加、删除及重组织操作,具有一定的参考价值,感兴趣的可以了解... 目录一、mysql分区表分类二、范围分区(Range Partitioning1、新建分区表:2、分

MySQL 定时新增分区的实现示例

《MySQL定时新增分区的实现示例》本文主要介绍了通过存储过程和定时任务实现MySQL分区的自动创建,解决大数据量下手动维护的繁琐问题,具有一定的参考价值,感兴趣的可以了解一下... mysql创建好分区之后,有时候会需要自动创建分区。比如,一些表数据量非常大,有些数据是热点数据,按照日期分区MululbU

SQL Server配置管理器无法打开的四种解决方法

《SQLServer配置管理器无法打开的四种解决方法》本文总结了SQLServer配置管理器无法打开的四种解决方法,文中通过图文示例介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的... 目录方法一:桌面图标进入方法二:运行窗口进入检查版本号对照表php方法三:查找文件路径方法四:检查 S

MySQL 删除数据详解(最新整理)

《MySQL删除数据详解(最新整理)》:本文主要介绍MySQL删除数据的相关知识,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录一、前言二、mysql 中的三种删除方式1.DELETE语句✅ 基本语法: 示例:2.TRUNCATE语句✅ 基本语

MySQL中查找重复值的实现

《MySQL中查找重复值的实现》查找重复值是一项常见需求,比如在数据清理、数据分析、数据质量检查等场景下,我们常常需要找出表中某列或多列的重复值,具有一定的参考价值,感兴趣的可以了解一下... 目录技术背景实现步骤方法一:使用GROUP BY和HAVING子句方法二:仅返回重复值方法三:返回完整记录方法四: