Skip to Content

Regarding Lock before BAPI

Hi,

I am using on FM: BAPI_BATCH_SAVE_REPLICA to change the order status from restricted to unrestricted.


I want to implement a lock before that and then unlock it afterwards.


How shall I do that?

Thanks.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • Posted on Oct 19, 2018 at 02:13 PM

    This BAPI creates a new batch based on an existing one, so I don't see why/how to lock the new batch that is not yet created.

    Am I missing something ?

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Francois, thanks for replying.

      We are using the BAPI just to change the work order status from Restricted to Unrestricted.

      This is the code:

      IF ls_batchstatus-restricted EQ abap_true.

      ls_batchstatus-restricted = ' '.
      ls_batchstatusx-restricted = abap_true.

      CALL FUNCTION 'BAPI_BATCH_SAVE_REPLICA'
      EXPORTING
      material = ps_outtab-matnr
      batch = ps_outtab-charg
      batchstatus = ls_batchstatus
      batchstatusx = ls_batchstatusx.

      but the thing is, sometimes I'm getting the message as "BATCH XXX OF MATERIAL XXX IS ALREADY LOCKED BY <User Name>". and if I just press ENTER, it is getting accepted.

      So when that's why I thought this must be a lock issue. I tested with "Wait up to 5 seconds" and it's working fine but it's not good practice to write a code like this. Hence want to add locks before and after that FM call.

  • Posted on Oct 19, 2018 at 02:45 PM

    OK then you just have to use this FMto enqueue the batch (it gives error if already locked) :

    VB_ENQUEUE_BATCH

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 19, 2018 at 03:12 PM

    Yes :-)

    And don't forget to commit.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 19, 2018 at 03:21 PM

    All right, thank you so mcuh.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 19, 2018 at 06:11 PM

    Hey, got the same message still.

    If I debug that FM, just for 10 sec(without changing anything) then no issues but if I execute directly then that message again.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 22, 2018 at 06:59 AM

    Could you try to replace the call of VB_ENQUEUE_BATCH with a call of ENQUEUE_EMMCH1E (or ENQUEUE_EMMCHA) using the _WAIT parameter and/or wrap this request for lock in some do loop, which would be better than a wild WAIT UP TO n SECONDS. The COMMIT or ROLLBACK WORK (or BAPI_TRANSACTION_*) will remove the lock.

    Question: under what circumstances are you calling the BAPI, in some BAdI at save/end of a transaction, in this case did you consider calling the BAPI in BACKGROUND UNIT/TASKto insure execution after previous transaction changes commited to database and locks removed?

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 22, 2018 at 03:13 PM

    Hi,

    If you think that the batch should be unlocked, you have still the possibility to call function DEQUEUE_ALL before you start your processing.

    About the call of a BAPI in background task, it may be necessary if you call it in an update task (the commit would generate a dump) but it does not seem to be the case here. However you can also try to use SET UPDATE TASK LOCAL before you call the BAPI and do the commit.

    BR

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.