`

<转>BAPI_TRANSACTION_COMMIT versus COMMIT WORK

    博客分类:
  • ABAP
阅读更多
转自:http://wiki.sdn.sap.com/wiki/display/ABAP/BAPI_TRANSACTION_COMMIT+versus+COMMIT+WORK
Many people continue using (or advising to use) COMMIT WORK after a call to a BAPI function module.

You must always call BAPI_TRANSACTION_COMMIT (not COMMIT WORK) if you have called at least one BAPI function module within the current LUW.

Here's why (inspired from this SDN thread):

By simply looking at BAPI_TRANSACTION_COMMIT code, we see quickly what is different from COMMIT WORK. It calls BUFFER_REFRESH_ALL function module right after COMMIT WORK.
So BAPI_TRANSACTION_COMMIT additionally refreshes a "BAPI buffer".
Here is what BAPI buffer is for:
Assuming your program calls BAPIs consecutively and use a COMMIT WORK/BAPI_TRANSACTION_COMMIT only at the end so that to commit all BAPI updates once (better performance).
As you know, BAPIs need to check errors like data missing in database. For example, the second BAPI may have to check the existence of data written by the previously called BAPI. The data doesn't exist in database yet, but as it knows it will be written later at COMMIT WORK time, it uses a buffer (memory) to store this information, so that no error is raised.
Let's suppose the update during the COMMIT WORK fails (for any reason), the data is not written to database. If you have not refreshed the buffer using BAPI_TRANSACTION_COMMIT, the next BAPI calls will consider that some data will exist later, that is wrong.
The same kind of logic applies to the rollback: you must call BAPI_TRANSACTION_ROLLBACK instead of ROLLBACK WORK. It will empty the BAPI buffer too. Here's why:

If you rollback the first BAPI using ROLLBACK WORK statement, you must absolutely refresh the buffer, otherwise the next BAPI could think that the data will exist and would attempt erroneously to write data.
All that is probably better explained in SAP Library documentation about BAPI buffer

To test a BAPI, you need to use a test sequence in SE37, for calling BAPI_TRANSACTION_COMMIT. See SDN wiki - Function Module Test Sequence.

For information:

SAP library documentation about BAPI template code shows why buffers were initially required at an older time: as only PERFORM ON COMMIT was available (CALL FUNCTION IN UPDATE TASK did not exist yet), all data had to be retained in memory (because the form is called once though registered several times).
Now, as only CALL FUNCTION IN UPDATE TASK should be used, it makes obsolete this documentation and the need for storing data in memory. But buffer is still in use as I explained above.
分享到:
评论

相关推荐

    BAPI_NETWORK_COMP_CHANGE 修改项目网络组件的BAPI

    - 如果没有错误,调用事务提交函数`BAPI_TRANSACTION_COMMIT`完成修改操作。 - 最后,更新项目网络组件的批准数量。 #### 核心知识点解析 - **BAPI接口调用**:通过上述步骤可以看到,BAPI接口提供了标准化的...

    用BAPI_PO_CHANGE修改(ME23N)PO出貨日期的方法

    - 如果没有错误并且不是测试模式,则提交事务(`BAPI_TRANSACTION_COMMIT`)。 5. **清理工作**: - 清除所有使用的临时表和变量。 #### 四、注意事项 - 在使用`BAPI_PO_CHANGE`修改PO时,需要确保有足够的权限,...

    创建及修改物料主数据

    本文将详细介绍如何使用BAPI_TRANSACTION_COMMIT创建及修改物料主数据,包括物料主数据的创建和修改、物料描述的设置、客户端层次物料数据的设置、物料类型的设置等。 物料主数据的创建 在SAP系统中,物料主数据是...

    BAPI_ACC_DOCUMENT_POST增强

    assign component 'POSNR' of structure &lt;l_struc&gt; to &lt;l_field&gt;. read table c_accit with key posnr = &lt;l_field&gt; into wa_accit. if sy-subrc is initial. move-corresponding &lt;l_struc&gt; to wa_accit. ...

    凭证导入BAPI_ACC_DOCUMENT_POST

    标题与描述中的“凭证导入 BAPI_ACC_DOCUMENT_POST”指向了一个特定的SAP系统功能,用于自动化导入财务凭证,尤其在银行流水与企业财务系统间建立接口时至关重要。此过程不仅涉及标准参数的传递,还触及了如何处理和...

    如何利用BAPI_SALESORDER_CHANGE修改vbak增强字段

    在SAP系统中,BAPI(Business Application Programming Interface)是一种标准接口,允许外部应用程序与SAP系统进行交互,包括创建、更改和查询业务数据。在本案例中,我们需要利用BAPI_SALESORDER_CHANGE来修改销售...

    采购订单BAPI增强数值型字段转换方法.docx

    &lt;x_ci_ekkodb&gt; = &lt;x_im_container&gt;. lf_done = cl_mmpur_constants=&gt;yes. ELSEIF im_name = 'CI_EKKODBX'. l_ci_ekkodbx = im_container. lf_done = cl_mmpur_constants=&gt;yes. ELSEIF im_name = 'CI_EKPODB'. ...

    BAPI_NETWORK_MAINTAIN 下达项目网络的BAPI

    ### BAPI_NETWORK_MAINTAIN:下达项目网络的BAPI #### 概述 在SAP系统中,**BAPI_NETWORK_MAINTAIN** 是一个用于维护和管理项目网络的业务应用程序接口(Business Application Programming Interface,简称BAPI)...

    sap abap常用bapi

    6. BAPI_CHARACT_CREATE/BAPI_CHARACT_CHANGE/BAPI_CHARACT_DELETE/BAPI_CHARACT_RENAME/BAPI_CHARACT_GETDETAIL/BAPI_CHARACT_ADDLONGTEXT/BAPI_CHARACT_REMOVELONGTEXT/BAPI_CHARACT_GETLONGTEXT/CARD_...

    关于用BAPI批量创建工艺路线

    这个是存储数据的,只有在调用完该函数后,工艺路线才真正创建,然后再加上 COMMIT WORK,如果成功,return 则不会返回信息。 我们可以使用 CP_CC_S_IMPORT_DATA 函数来解决 BAPI_ROUTING_CREATE 不可以创建定额...

    BAPI-ACC-DOCUMENT-POST 结构字段扩展

    ASSIGN COMPONENT 'ITEMNO_ACC' OF STRUCTURE &lt;l_struc&gt; TO &lt;l_field&gt;. READ TABLE c_accit WITH KEY posnr = &lt;l_field&gt; INTO wa_accit. IF sy-subrc IS INITIAL. MOVE-CORRESPONDING &lt;l_struc&gt; TO wa_accit. ...

    BAPI_PO_CREATE.zip_bapi_po_create help

    通过JCo接口利用BAPI函数创建PO订单

    创建销售订单

    BAPI_SALESORDER_CREATEFROMDAT2是SAP系统中创建销售订单的API接口,通过调用这个接口,可以快速创建销售订单。 在创建销售订单时,需要设置订单的头信息、项目信息、伙伴信息和计划信息等。头信息包括订单类型、...

    实用BAPI做内部调拨

    在SAP系统中,BAPI(Business Application Programming Interface)是一种预定义的函数模块,用于在不同组件之间进行集成和自动化业务流程。本示例中的"实用BAPI做内部调拨"是指使用BAPI_GOODSMVT_CREATE来执行物料...

    BAPI based on existing SAP database tables 操作手册

    - BAPI表扩展的命名规范是&lt;namespace&gt;BAPI_TE_&lt;table_name&gt;,其中&lt;namespace&gt;是用户自定义的命名空间,&lt;table_name&gt;是原SAP表的名字。 - 由于结构名称长度限制,可能需要缩短名称,但应保持名称的可读性。 - 每个...

    LSMW_BAPI_MM02_CS01.xlsx

    LSMW_BAPI_MM02_CS01

    预置发票批量过帐

    调用BAPI函数:BAPI_INCOMINGINVOICE_POST实现批量MIR4功能。

    BAPI_GOODS的函数说明

    这是SAP ABAP 中BAPI GOODS的函数说明,有利于用户进行更深入的了解

    SAP 所有BAPI的清单

    SAP中很多情况下客户提出增强的需求时,我们通常会用到BAPI或者BADI。虽然你可以在SAP中直接输入TCd:BAPI来查找。但是并不是所有的BAPI都能查得到的。希望这个清单能够帮到你。

    BAPI_User_Guide word文档

    《BAPI用户指南》 本指南旨在为SAP开发者提供有关BAPI(Business Application Programming Interface)的详尽信息,帮助他们更好地理解和运用这些接口。BAPI是SAP系统中的核心组件,它允许外部应用程序与SAP系统...

Global site tag (gtag.js) - Google Analytics