Transactional RFC 事务性 RFC

2022-02-11 17:26发布


          点击此处--->   EasySAP.com 群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)

image.png


IDOC 接口底层就是使用事务性RFC


Description

描述


As of release 3.0, you can execute function modules asynchronously in another SAP system or in an external program. The function modules are not called immediately, but when the next COMMIT WORK is executed. Until this time, the calls are collected in an internal table. The calls for each destination thus constitute a Logical Unit of Work ( LUW)).

从 3.0 版开始,您可以在另一个 SAP 系统或外部程序中异步执行功能模块。功能模块不会立即调用,而是在执行下一个 COMMIT WORK 时调用。直到此时,调用都收集在一个内部表中。因此,每个目的地的调用构成了一个逻辑工作单元 (LUW)。


When a COMMIT WORK statement occurs, the stored calls are executed by the next free work process in the order in which they were called. If there are updates before COMMIT WORK, the asynchronously called function modules are not executed until all the update function modules have been successfully processed.

当 COMMIT WORK 语句发生时,存储的调用将由下一个空闲工作进程按照调用顺序执行。如果在 COMMIT WORK 之前有更新,则异步调用的功能模块要等到所有更新功能模块都处理成功后才会执行。


The asynchronous tRFC,  which is like a transaction, guarantees that either all database operations are executed or, if a function module terminates, all rolled back. If an LUW is executed without errors, it cannot be executed again (it is executed exactly once). In some cases, it may be necessary to program the roll back of an LUW, (for example, because a table is locked). The function module RESTART_OF_BACKGROUNDTASK is used for this. It executes a rollback and the LUW is executed again at a later time. A transaction ID is assigned to each LUW. You only need to know this, if, for example, you want to wait for the function module IN BACKGROUND TASK to be executed.

异步 tRFC 类似于事务,保证所有数据库操作都被执行,或者,如果功能模块终止,则全部回滚。如果 LUW 执行无误,则不能再次执行(它只执行一次)。在某些情况下,可能需要对 LUW 的回滚进行编程(例如,因为表被锁定)。为此使用了功能模块 RESTART_OF_BACKGROUNDTASK。它执行回滚,稍后再次执行 LUW。为每个 LUW 分配一个事务 ID。您只需要知道这一点,例如,如果您想等待功能模块 IN Background TASK 被执行。


The function module ID_OF_BACKGROUNDTASK returns the ID of the LUW. It must be called after the first CALL... IN BACKGROUNDTASK and before COMMIT WORK. You can use the function module STATUS_OF_BACKGROUNDTASK and the ID to find out later whether the LUW ran successfully. Normally, the LUW is executed immediately after COMMIT WORK in the specified target system. If it is to be started at a specific time, you can set a time with the function module START_OF_BACKGROUNDTASK. This function module must also be called within the LUW, that is, after the first CALL... IN BACKGROUNDTASK and before COMMIT WORK.

功能模块 ID_OF_BACKGROUNDTASK 返回 LUW 的 ID。它必须在第一次 CALL... IN BackgroundTASK 之后和 COMMIT WORK 之前调用。稍后可以使用功能模块STATUS_OF_BACKGROUNDTASK 和ID 来查看LUW 是否运行成功。通常,LUW 会在指定目标系统中的 COMMIT WORK 之后立即执行。如果要在特定时间启动,可以通过功能模块 START_OF_BACKGROUNDTASK 设置时间。该功能模块也必须在 LUW 内调用,即在第一次 CALL... IN BackgroundTASK 之后和 COMMIT WORK 之前。


Technical Implementation

技术实施


All calls are recorded in tables ARFCSSTATE and ARFCSDATA. Each LUW is identified by a unique ID. At the COMMIT WORK, the calls stored under this ID are executed on the relevant target system. The system function module ARFC_DEST_SHIP transports the data to the target system and the function module ARFC_EXECUTE executes the stored function calls. If an error or an exception occurs during one of the calls, all database operations started by the preceding calls are rolled back and an appropriate error message is written to the file ARFCSSTATE. You can analyze this error message with transaction SM58.

所有呼叫都记录在表 ARFCSSTATE 和 ARFCSDATA 中。每个 LUW 都由一个唯一的 ID 标识。在 COMMIT WORK 中,存储在此 ID 下的调用在相关目标系统上执行。系统功能模块 ARFC_DEST_SHIP 将数据传输到目标系统,功能模块 ARFC_EXECUTE 执行存储的函数调用。如果在其中一个调用期间发生错误或异常,则由前面的调用启动的所有数据库操作都将回滚,并将相应的错误消息写入文件 ARFCSSTATE。您可以使用事务 SM58 分析此错误消息。


If an LUW runs successfully in the target system, the function module ARFC_DEST_CONFIRM is called and confirms the successful execution in the target system. Finally, the entries in ARFCSSTATE and ARFCSDATA are deleted.

如果 LUW 在目标系统中成功运行,则调用功能模块 ARFC_DEST_CONFIRM 并确认在目标系统中成功执行。最后,删除 ARFCSSTATE 和 ARFCSDATA 中的条目。


If the target system cannot be reached, for example, because the connection is not active, the report RSARFCSE is scheduled as a background job with the ID as a parameter, and is called at regular intervals. You can display the standard values for this in transaction SM58 by choosing "Info -> System Setting". If you want to use a separate setting for each destination, you can specify this with the tRFC options in Transaction SM59. Alternatively, you can use the enhancement SABP0003 (maintain with transaction CMOD) to override this setting by destination, user name, and so on. If no connection is made during the relevant time period, the entry in ARFCSSTATE is deleted after a time which you can also specify in the enhancement. The deletion is done in the background in report RSARFCDL.

如果无法访问目标系统,例如,因为连接未激活,则报告 RSARFCSE 将作为后台作业调度,并将 ID 作为参数,并定期调用。您可以通过选择“信息 -> 系统设置”在事务 SM58 中显示此标准值。如果您想为每个目标使用单独的设置,您可以使用事务 SM59 中的 tRFC 选项指定此设置。或者,您可以使用增强 SABP0003(使用事务 CMOD 维护)通过目标、用户名等覆盖此设置。如果在相关时间段内未建立连接,则 ARFCSSTATE 中的条目将在您也可以在增强中指定的时间后删除。删除是在报表 RSARFCDL 的后台完成的。


Further notes

补充说明


Debugging

调试


Call the relevant transaction in debugging mode, choose "Goto -> Settings" and set the selection field "In background task:..." If you do this, the LUW is not executed immediately, and you can therefore use transaction SM58 to execute it in debugging mode.

在调试模式下调用相关事务,选择“Goto -> Settings”并设置选择字段“In background task:...”如果这样做,LUW不会立即执行,因此可以使用事务SM58执行它处于调试模式。


RFC API

RFC API


You can also execute programs asynchronously in 'C'-implemented function modules (connection type TCP/IP in transaction SM59). Implementation of the function modules occurs as usual in connection with the RFC API. This contains the function modules ARFC_DEST_SHIP and ARFC_DEST_CONFIRM, which call the appropriate functions.

您还可以在“C”实现的功能模块中异步执行程序(事务 SM59 中的连接类型 TCP/IP)。与 RFC API 相关的功能模块的实现与往常一样发生。这包含调用相应函数的函数模块 ARFC_DEST_SHIP 和 ARFC_DEST_CONFIRM。


Restrictions:

限制:


•The Microsoft Windows API does not yet support asynchronous calls.
•The once-only execution must be guaranteed by the implementation of the function modules.

•Microsoft Windows API 尚不支持异步调用。
• 必须通过功能模块的实现来保证一次性执行。

赞赏支持