Commit work in BAPI

Hi Experts,
Why should not use COMMIT WORK in BAPI ? If I give COMMIT WORK in BAPI what is will happen?

Hi,
1. Why should not use COMMIT WORK in BAPI
I suppose you are asking this in context of Z BAPI and not standard BAPI.
The reason why we should not use is bcos SAP has recommended the design for BAPI in that manner.
2. If I give COMMIT WORK in BAPI what is will happen?
   Well, as such there is nothing wrong going to happen. (Unless there is some dependent update in database)
To give you an example.
Suppose we have to update ZTABLE1 and ZTABLE2- the code for which is in TWO SEPARATE BAPIs.
Also it is requierd that if one fails, then other should not get updated. Either All or Either None case.
ZBAPI1 - TABLE1
ZBAPI2  - TABLE2
If ZBAPI1 is called and we have written commit work inside that, TABLE1 will get updated.
Then if there is any error in ZBAPI2, then TABLE2 will not get updated in hence the information will be INCONSISTENT.
3. Hence, the flow should be like this; (No commit work inside the bapi)
Main Program.
Call ZBAPI1.
Call ZBAPI2.
COMMIT WORK.
This will ensure that ALL or NONE happens.
regards,
amit m.

Similar Messages

  • Commit work and wait after bapi execution not working

    Hi experts,
    I have a requirement from my client that consists on posting 2 documents and then clearing them.
    Right now Iu2019m posting the first 2 documents using BAPI_ACC_DOCUMENT_POST and for clearing both documents Iu2019m using Tcode F-51 but sometimes it's giving me an error clearing the documents because after the second bapi run, posting the second document, apparently all went right and a document number it's returned but the database doesnu2019t updated the doc number.
    Iu2019m using commit work and wait, and already tried BAPI_TRANSACTION_COMMIT,  but it doesnu2019t work sometimes, and the only solution that i found was the Wait up 1 second command , which it's slowing the program execution.
    i think the problem it's on the bapi posting execution, due to a lag on the database side, but Iu2019m not sure...
    Did anyone already had this problem? Has anyone has a solution for this?
    Thanks in advance
    Best Regards
    João Martins

    Hi,
    Normally every BAPI will work on Update task so that the data will be updated once the commit work is done. For the commit work, we will normally call the bapi function module - BAPI_TRANSACTION_COMMIT. It should work.
    In your case, just try the below option:
    Please call the bapi - BAPI_ACC_DOCUMENT_POST & BAPI_TRANSACTION_COMMIT in a seperate function module and call this function module in your program (just pass the import / export / table parameters accordingly).
    For the information, I had once a similar type of issue and it got solved once I did like the above.
    Regards,
    Selva K.

  • COMMIT WORK AND WAIT does not work

    Hello,
    I know this question has been asked many times in various forums. But the fact remains that there is no definitive solution found for this problem which does not involve WAIT UP TO n SECONDS or SELECT until the DB commit has been completed.
    We have an IDoc based inbound interface for creating Project Defintion and WBS Elements. Here is how the code looks like in the processing function module:
    * Create Project Defintion
    CALL FUNCTION 'BAPI_PROJECTDEF_CREATE'
      EXPORTING
        project_definition_stru = lwa_proj_bapi
      TABLES
        e_message_table         = lt_messages.
    * If no errors
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.
    * Other code
    * Create WBS Element (BAPI could not be used because not all fields are allowed to be updated)
    CALL TRANSACTION 'CJ11'
    Now while creating the WBS Element, transaction CJ11 returns an error that 'Project does not exist'. This is not correct because the same Project was successfully created in the previous step.
    It is clear that the problem is because of the delay in database commits.
    This happens only with few IDoc's and not all of them. And of course, the problem does not occur if I induce WAIT UP TO n SECONDS after BAPI_TRANSACTION_COMMIT. But this is not the best practice.
    The question is why BAPI_TRANSACTION_COMMIT does not wait even though we are forcing it to?
    Thanks in advance
    Sagar Acharya

    Suhas wrote:
    But i am baffled that although the COMMIT has happened earlier why is the data not updated in the DB ?
    Well, it's just a [COMMIT WORK|http://help.sap.com/abapdocu_70/en/ABAPCOMMIT.htm] and not a [COMMIT WORK AND WAIT|http://help.sap.com/abapdocu_70/en/ABAPCOMMIT.htm#@@AND%20WAIT@@COMMIT%20WORK@@]. Let me quote the ABAP help:
    If you do not specify the addition AND WAIT, the program does not wait until the update work process has executed it (asynchronous updating), but instead is resumed immediately after COMMIT WORK. However, if the addition AND WAIT is specified, program processing after COMMIT WORK will not continue until the update work process has executed the high-priority update function modules (synchronous updating).
    @Sagar Acharya: Well, I thought you were looking for an explanation why sometimes the project isn't created (and you only had posted coding that showed details for step 1) - I'm trying hard, but my mind reading skills are rather limited yet...
    So let's think about step 2 and 3: I assume that you made sure that your coding always references the correct WBS element. Again the commit (without wait) is done already via CJ11 (e.g. check form BUCHEN in SAPLCJWB). I'd expect though that the synchronous update mode should make this work. Since it doesn't, I'd try local update mode, which is what I'd choose in your case anyhow.
    Apart from that my mind is pretty blank, except for the usual silly things to check. E.g. are you sure you're coding is correct, you are handling all return messages and log them for inspection later (e.g. application log), you are certain that the WBS was actually created by the same IDoc that throws the fit (and IDoc was not reprocessed), etc.
    So maybe somebody else has better ideas...

  • COMMIT WORK and WAIT FOR n SECONDS

    I am designing a WebDynpro Java application.  It makes an update call followed immediately by a display call which should return the data that was just updated.  However, it appears that there is some DB latency involved and the data takes a few seconds to update.  The application displays old data if the display call is performed too quickly after the update call.
    All suggestions I could find point to having a Thread sleep on the Java side for a few seconds or have a WAIT FOR n SECONDS and/or COMMIT WORK AND WAIT statement in the ABAP function module.  Neither of these solutions is acceptable in a company-wide application where database latency could vary significantly based on traffic.
    I tried all kinds of functions (i.e. BAPI_TRANSACTION_COMMIT) as well as various forms of COMMIT WORK... nothing except a WAIT works correctly.  There must be a statement out there that waits for the database write to be complete!  How is this solved without picking an arbitrary WAIT time?  What am I missing?
    Thanks in advance!

    You can write the other way.
    declare one variable
    data : wa_try type i.
    wa_try = 10. -> set as 10 ,even you do not get value ,keep on incresing.
    after BAPI FM
    you can call comitt fm.
    after BAPI_TRANSACTION_COMITT
    just use simple logic.
    do wa_try.
    select * from table into table
                                  where record = bapi fm record ( You get in RET2 Message).
    if sy-subrc eq 0.
    exit.
    endif.
    Thanks
    Seshu

  • COMMIT WORK - performance problem

    Dear Fellow SDNers,
    I seek your help on the following problem:
    Scenario : Inbound idoc which updates an Outbound delivery with Picked quantity, posts the goods issue and then creates billing document
    Approach : I am using the function module SD_DELIVERY_UPDATE_PICKING to update the delivery from the idoc data and to post goods issue. Thereafter, i use BAPI_BILLINGDOC_CREATEMULTIPLE to create the billing document. Before calling this BAPI, I use a COMMIT WORK statement to update the relevant tables so as to enable invoice creation properly.
    Problem: The COMMIT WORK statement takes a lot of time to execute (I have no update tasks that could lead to this), so much that the idoc (probably) has a timeout and ends up in status 64. As a result, the succeeding part of the code (after COMMIT WORK) is not executed and the billing document is not created.
    When I debug this, the COMMIT WORK statement leads to a strange screen (which looks like a blank report output screen, with its title as "UPDATE CONTROL". However (of course), there is no timeout while debugging and the billing document is successfully created.
    Could anyone provide some pointers to solve this problem?
    regards,
    Priyank

    i have a custom function module Y_IDOC_INPUT_WMSPICK001 which is responsible for idoc inbound processing. SAP PI sends the inbound data to ECC and once this is done, this function module is executed.
    This FM has the following code sequence inside it...
    1) Call the FM SD_DELIVERY_UPDATE_PICKING
    2) COMMIT WORK AND WAIT.
    3) Call the BAPI_BILLINGDOC_CREATEMULTIPLE
    Step1 is successfully executed,  the step 2 takes a long time, and after that, the step 3 is not executed at all and the idoc ends up with a yellow light (status 64).
    hope it clarifies what I am doing
    regards,
    Priyank

  • Does Update function module gets executed after Commit Work?

    Hi Gurus,
    I have a BAPI with a Commit work. Does update function module V1 , V2 - i need mainly about the sequence of V2, gets executed after Commit work or before Commit work.
    Thanks

    Pl refer to SAP help on the same as follows.
    https://help.sap.com/saphelp_nw04/helpdata/en/e5/de86e135cd11d3acb00000e83539c3/content.htm
    Regards,
    Naveen Vishal

  • Regarding COMMIT WORK

    Hi,
    I am using two BAPIs 'BAPI_ACC_ACTIVITY_ALLOC_POST' and 'BAPI_NETWORK_CONF_ADD' in my custom function module. These two BAPIs are used  as explained below:
    1) Fisrt the BAPI 'BAPI_ACC_ACTIVITY_ALLOC_POST'  is called. If sy-subrc NE '0', the error messages are read.
    2) Then the BAPI 'BAPI_NETWORK_CONF_ADD' is called. If sy-subrc NE '0', its error messages are read.
    3) If there is no error for the two BAPIs called above, then the actual posting is done by calling the BAPI
       'BAPI_ACC_ACTIVITY_ALLOC_POST'. If sy-subrc EQ 0, Commit work.
    I would like to know if the Commit work in third step will commit the changes of the steps 1 and 2 as the the statement COMMIT WORK completes the current SAP LUW.
    Or will it commit the step 3 only.
    Thanks & Regards,
    Soumya.

    Hi soumya,
    you can rollback for the step 1& 2 if sy-subrc ne 0.
    and then use the comit work if sy-subrc eq 0 for step 3.
    Hope this will help you.
    regards,
    Phani.

  • Update was terminated when we do commit work twice in short time

    Hi Experts,
                i have one Data bas update problem. My requirement is to create contracts in CRM with new item category(suppose ZSFT) than what is determined(ZSRT). i am using CRM_ORDER_MAINTAIN FM to create contracts after that i am calling CRM_ORDER_SAVE to save transaction then COMMIT WORK key word to commit in data base. Since transaction is created with Determined item category(ZSRT) i  am calling change transaction bapi  BAPI_BUSPROCESSND_CHANGEMULTI to change item category after that BAPI_BUSPROCESSND_SAVE to save transaction and BAPI_TRANSACTION_COMMIT to commit the work. but second commit is not happening instead error message "Update was terminated" recieved from author "XXXX". when i created test program with BAPIs to change already created contracts to change item category it is working fine.
    Any body has any clue.
    Thanks in advance
    Siva

    Hello Siva, Is your problem solved ? I have the same error and unable to update the partner info on Service confirmation.
    Here is what I'm trying to acheive.. I'm working on an interface that creates a docflow and creates service confirmation against existing service order. In the confimation file when I have new ZAPP((partner function ZAPP) I need to delete ZAPP that gets copied over from service order into the confirmation in docflow. Right now, in my first CRM_ORDER_MAINTAIN call I have one entry for new ZAPP  and I have It_docflow populated. This creates two ZAPPs on the confirmation. I need to delete ZAPP on the confirmation that is copied over from service order.
    Right now I'm reading the confirmation and trying to delete the ZAPP but after my second crm_order_maintain,order save and commit call sequence I'm getting this error update was terminated.
    Experts any help on how to get around this issue would be highly appreciated.
    Thanks

  • Data lock even after commit work and wait

    Hi Experts,
    Data is still locked even after commit work and wait step has run, which made me very confusing.
    The following are the details:
    These steps are in a FOP.
    Step1: Change Move-in Date of a move-in document in background after get the new move-date from user.
    Step2: Run BAPI_TRANSACTION_COMMIT and pass the wait parameter.
    Step3: Bring move-in document transaction to the user for other information changes.
               After the user confirms the changes and presses SAVE button, error message shows that the move-in document is still locked. But no other transaction is opened for the specified move-doc changing.
    Does any1 have any idea on this? How can I solve this issue?
    Thanks in advance and points will be rewarded.
    Vincent

    Hi,
    Normally every BAPI will work on Update task so that the data will be updated once the commit work is done. For the commit work, we will normally call the bapi function module - BAPI_TRANSACTION_COMMIT. It should work.
    In your case, just try the below option:
    Please call the bapi - BAPI_ACC_DOCUMENT_POST & BAPI_TRANSACTION_COMMIT in a seperate function module and call this function module in your program (just pass the import / export / table parameters accordingly).
    For the information, I had once a similar type of issue and it got solved once I did like the above.
    Regards,
    Selva K.

  • DUMP with Commit work and wait

    Hi all!! I need your help again!!
    I have this:
      WAIT UP TO 1 SECONDS.
                          UPDATE zpsc_ofertes
                          SET status = 'ENTRA'
                              status_v = 'CO/AA'
                          WHERE oferta = zpsc_ofertes-oferta
    AND versio = var_vers_destino.
    CALL FUNCTION 'STATUS_UPDATE_ON_COMMIT'.
        COMMIT WORK AND WAIT.
    CALL FUNCTION 'BUFFER_REFRESH_ALL'
    That code creates a dump... Why could be this problem??
    Thanks!!

    Let's see.
    The current application triggered a termination with a short dump.
    ¿Qué ha sucedido?
    The current application program detected a situation which really
    should not occur. Therefore, a termination with a short dump was
    triggered on purpose by the key word MESSAGE (type X).
    ¿Qué puede hacer?
    Print out the error message (using the "Print" function)
    and make a note of the actions and input that caused the
    error.
    To resolve the problem, contact your SAP system administrator.
    You can use transaction ST22 (ABAP Dump Analysis) to view and administer
    termination messages, especially those beyond their normal deletion
    date.
    The code...
    000010   *
    000020   ***INCLUDE LPS_BAPIF01 .
    000030   *
    000040   *&
    000050   *&      Form  CHK_PRECOMMIT
    000060   *&
    000070   *       check precommit
    000080   *
    000090   FORM chk_precommit.
    000100
    000110     DATA: chk_precommit_ok TYPE c,
    000120           chk_error        type c.
    000130
    000140     CALL FUNCTION 'PS_FLAG_GET_GLOBAL_FLAGS'
    000150          IMPORTING
    000160               e_precommit_ok = chk_precommit_ok
    000170               e_error        = chk_error.
    000180
    000190     IF chk_precommit_ok = space.
    000200   *   Precommit wurde noch nicht aufgerufen.
         >       MESSAGE x030(cnif_pi).
    000220     ELSEIF chk_precommit_ok <> 'Y'.
    000230   *   Precommit wurde nicht erfolgreich durchlaufen.
    000240       MESSAGE x033(cnif_pi).
    000250     elseif not chk_error is initial.
    000260   *   At least one single BAPI failed
    000270       MESSAGE x056(cnif_pi).
    000280     ENDIF.
    000290
    000300   * commit work was called successfully after the precommit
    000310     PERFORM ps_bapi_init_global_variables.
    000320
    000330   ENDFORM.                    " CHK_PRECOMMIT
    000340

  • Issue with Commit Work and Wait.

    Hi All,
    None of the programs are working in my system which are calling BAPI BAPI_TRANSACTION_COMMIT.
    On COMMIT WORK AND WAIT statement, the process is going into indefinite loop. Everything was fine till last Thursday and there are no updates or patch level change or notes applied in the system.
    Please advice.

    <div style="text-align:left">We tried everything but still the issue is there.</div>
    Normally it's much easier to get help if you try to be as detailed as possible when explaining the problem and what exactly you have tried. No offense, but tried everything most likely translates into almost everything...
    Some information/checks I'd be looking for:
    <ul style="list-style:square!important">
    <li>What functions are (or coding is) involved? Are they all standard or custom?</li>
    <li>Have you tried update debugging and/or the usual traces (runtime analysis, SQL trace, etc.)?</li>
    <li>What do you see in the process overview?</li>
    <li>What about system log, developer trace, database logs/alerts, etc.?</li>
    </ul>
    Obviously my list is much too short and incomplete - yours must be longer. If you share your results (including your exchange with SAP) I suspect you have a better chance (though of course no guarantee) of somebody providing a valuable clue.
    Not sure if it's just me, but the part that sounds so odd and suspicious is that you only mention commits via BAPI_TRANSACTION_COMMIT. As this is just a wrapper around a COMMIT WORK I'm tempted to think it's the functionality that's invoked before (i.e. linked to the registered update functions/modules). Without any additional knowledge though, my first shot was for general update problems (which you ruled out).

  • Commit work and wait don't work,why

    Hi All,
    I call BAPI 'BAPI_PO_CREATE1' and create PO, then commit via
    commit work and wait.
    after creating, query the new PO via
    SELECT ebelp pstyp INTO TABLE lt_ebelp
      FROM ekpo
      WHERE ebeln = p_lv_ebeln.
    but no result.
    If creating and waiting a moment, it do work.
    why, I already used 'commit work and wait' but not 'commit work'.
    thanks.
    regards.
    dou

    Okay ,first check whether po number is getting saved or not .
    If po is saving then use BAPI_TRANSACTION_COMIITT FM ..
    Now check ur select query like : Since wait upto n seconds ( This may not work)
    data : n Type i.
    n = 10.
    write the below code after  BAPI_TRANSACTIOn_COMITT.
    do n times.
    select query
    if sy-subrc eq 0.
    exit.
    endif.
    enddo.
    still document number is not coming ,testing purpose increate n as 20 and see the results.
    Thanks
    Seshu

  • Is 'Commit Work' statement necessary?

    Is it mandatory to issue 'Commit Work' statement to terminate the program in SAP LUW? If not provided would the program go into infinite loop?

    ... just before the thread gets locked:
    There is no such thing as an implicit commit work. The implicit commit is a database commit, that means after every process interruption as i.e. processing of any screen and the end of program execution all database activities are committed, they can not be rolled back.
    The explicit ABAP statement COMMIT WORK will termiante the current LUW and, additionally start execution of all asynchronous database operations (Call function in update task), start all PERFORM ON COMMIT routines.
    Most BAPI calls need a subsequent COMMIT WORK, better issued by function Call BAPI_TRANSACTION_COMMIT.
    The documentation has more information. One major truth is: In 'simple' programs that do some INSERTS, UPDATES and MODYFYs on database tables, you do not need any COMMIT WORK. And if screen processing happens afterwards, you can not ROLL BACK.
    Regards,
    Clemens

  • COMMIT work in BADI

    Hi all,
    Can anyone tell me about, is COMMIT WORK is allowed in BADI or USER EXIT?
    If not, what is the aalternative for that?
    Thanks in advance.
    Best Regards,
    Prasad

    Hi Prasad.
    I would like to suggest a couple of references,
    [SDN - Reference - Call Transaction / Bapi and Commit work in a Update task|Call Transaction / Bapi plus Commit work in a Update task?;
    [SDN - Reference - COMMIT WORK on BADI BUPA_GENERAL_UPDATE|COMMIT WORK on BADI BUPA_GENERAL_UPDATE;
    Hope that's usefull.
    Good Luck & Regards.
    Harsh Dave

  • Automatic commit work after class method?

    Hi guys,
    after calling a class method, is there an automatic commit work? Or do I have to insert a commit work into the class method?
    At which points, a commit work is automatically called?
    Regards,
    Basti

    Hi,
    there is so much confusion about commit, commit work and rollback:
    1. At the end of LUW and at every interruption (screen display including message issued, RFC calls,...)  an implicit database commit occurs.
    2. COMMIT WORK will trigger all update task processes that have been registered before (call function in update task, perform on commit). Most BAPI functions use perform on commit. An implicit database commit ist not a COMMIT WORK.
    3. Rollback work will delete all pending update tasks inclusing all database updates not yet commited.
    4. Only the 'Master'of any process should rule the COMMIT WORK because COMMIT WORK means that ALL pending update tasks are executed. So only the caller on top of the hierarchy should issue the COMMIT WORK because a later ROLLBACK is not possible - ROLLBACK only works if not y<et committed.
    These rules work independent of programming feature used - nothing different in oo.
    Regards
    Clemens

Maybe you are looking for

  • Mass Activity Changes

    I have a role with lots of t_code and i would like to give them full authorization, but change all ACTIVITY to 03. is there a way to change them all at once. thank you

  • CCMS in the context of XI

    I am trying to figure out how CCMS relates to XI, and how it would be used in XI. I've read through forum threads, help.sap.com, presentations, and blogs. I am still confused because I know that CCMS expands across XI and to other components, includi

  • Photoshop button as lightbox thumbnail?

    I made a photoshop button that I'd like to have trigger a movie in a lightbox, but it's not showing rollover state. Is this use for photoshop button possible? 

  • Adobe Flash Palyer for Nokia E50

    Good Day, Does anyone know how to get the Adobe Mobile flash player on a E50 cellphone.

  • Passing diff internaltables in single perform statement

    hi all, hw can v pass diff internal tables to a single form. 4 internal tables with diff structures each time i have to pass 1 internal table to that form.... hw can it possible, can anybody explian me with example..... <REMOVED BY MODERATOR> thanks