Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

sales document getting locked while updating

Former Member
0 Likes
4,897

Hi all,

WE ARE WORKING ON A PRODUCT WHERE WE USE RFCs to update the data. In that I am updating the sales document this document is getting locked before i am going to update the data using bapi. And i am getting error as Sales document is currently under processing. But the document is not open. may i know how to eliminate the locks before posting using bapi.

Thanks & Regards

sreehari p

1 ACCEPTED SOLUTION
Read only

Clemenss
Active Contributor
0 Likes
3,259

Hi sreehari reddy,

well, if the sales document is locked, it may have been changed or created and the update task is still busy saving it.

You can use a loop trying to lock it, when you are succesful locking it, you unlock it and then call the BAPI - the BAPI does all the locking required, so it can't work if you lock the document before.

WHILE lv_locked is initial.

CALL FUNCTION 'ENQUEUE_EVVBAKE'

...

  IF SY-SUBRC = 0.

    lv_locked = 'X'.

  ELSE.

    WAIT UP TO 1 SECONDS.

  ENDIF.

ENDWHILE.

CLEAR lv_locked.

CALL FUNCTION DEQUEUE_EVVBAKE'

  ...

CALL FUNCTION  'BAPI' ...

In the above code, you should integrate a max lock try counter to event endless loops for orders locked by a sleeping user.

Regards,

Clemens

Hi all,

WE ARE WORKING ON A PRODUCT WHERE WE USE RFCs to update the data. In that I am updating the sales document this document is getting locked before i am going to update the data using bapi. And i am getting error as Sales document is currently under processing. But the document is not open. may i know how to eliminate the locks before posting using bapi.

Thanks & Regards

sreehari p

11 REPLIES 11
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
3,259

"But the document is not open" - May be opened by some body else not at your location.

Read only

Former Member
0 Likes
3,259

Hi Sreehari,

The doucment might be opened somewhere otherwise you wouldn't get such a message. In your code itself, before calling BAPI, first lock your sales document and after your processing unlock it using function module. This is a better approach while updating documents.

Regards,

Sindhu Pulluru.

Read only

Former Member
0 Likes
3,259

Hi,

Locked the document before processing your BAPI.

PARAMETERS: p_so LIKE vbak-vbeln OBLIGATORY MEMORY ID aun.

CALL FUNCTION 'ENQUEUE_EVVBAKE'
       EXPORTING
         mode_vbak      = 'E'
         vbeln          = p_so
         mandt          = sy-mandt
       EXCEPTIONS
         foreign_lock   = 1
         system_failure = 2
         OTHERS         = 3.
     IF sy-subrc NE 0.
       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
       WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

     ELSE.

     " process your BAPI here.

    ENDIF.

  If the document is open to someone or somewhere, this FM will throw an error message saying who uses the document.

Regards,

Jake.

Read only

0 Likes
3,259

HI

I had used Enqueue and dequeue locks . But as it is already locked I am getting Exception as Foreign lock in the enque FM and it is not getting locked . and the same error message currently under procssing.

Thanks & Regards

sreehari p

Read only

0 Likes
3,259

Then, sales document might already be locked in your RFC. Just try updating without using enqueue function.

Regards,

Sindhu Pulluru.

Read only

0 Likes
3,259

Hi Sreehari,

If you are getting exception that the document is having a foreign lock, you should stop the processing or write logic to try after sometime.

May be some other program might be accessing the same document at that time. so first analyse the SM12 lock entries to find out who has locked the document.

Regards,

Karthik D

Read only

Former Member
0 Likes
3,259

IMHO, programmatic modifications to sales orders are often not a good idea, particularly if these will be done during "normal" staff work hours.  You will very frequently find sales order documents locked, or you will not be able to obtain an exclusive lock because the order is open on some user's desktop.

In addition, SD db updates are a rather lengthy process, due to the sheer number of tables that are maintained in SD.  So, after you do an update, you will have a period of time in which you and all other users will not be able to open that order for update. That is a given in SD, and something most of us who have worked with SD have had to handle. 

You would be much more likely to succeed if you were doing the updates while the staff is not working, and while there are no scheduled jobs to create deliveries, etc., running in the system.

Read only

0 Likes
3,259

I couldn't agree more with Break Point, especially with RFC. If you used IDocs, they at least have a re-processing feature already available.

Otherwise as already suggested, write some logic to re-try for fixed number of times with some interval. Do not use ENQUEUE before BAPI since it already contains the locking mechanism and you'd be just, essentially, locking out yourself.

Read only

Clemenss
Active Contributor
0 Likes
3,260

Hi sreehari reddy,

well, if the sales document is locked, it may have been changed or created and the update task is still busy saving it.

You can use a loop trying to lock it, when you are succesful locking it, you unlock it and then call the BAPI - the BAPI does all the locking required, so it can't work if you lock the document before.

WHILE lv_locked is initial.

CALL FUNCTION 'ENQUEUE_EVVBAKE'

...

  IF SY-SUBRC = 0.

    lv_locked = 'X'.

  ELSE.

    WAIT UP TO 1 SECONDS.

  ENDIF.

ENDWHILE.

CLEAR lv_locked.

CALL FUNCTION DEQUEUE_EVVBAKE'

  ...

CALL FUNCTION  'BAPI' ...

In the above code, you should integrate a max lock try counter to event endless loops for orders locked by a sleeping user.

Regards,

Clemens

Read only

Former Member
0 Likes
3,259

U can unlock the document by T-Code: SM12.

But before you can manually delete lock entries, you must make sure that there
are no processes active which need the objects in question to be locked
(transaction, update). Otherwise, there is the danger that the objects which are
no longer protected can be changed by several processes at once and, as a
result, become inconsistent and incorrect.

once unlock sales order u can lock by using BAPI.

As break point says :  you will do the updates while the staff is not working, and while there are no scheduled jobs to create deliveries, etc., running in the system.

Regards

Read only

0 Likes
3,259

Hi Ravi,

yes I remember using SM12 to delete locks 10 or more years ago.

Today, it is not possible to have lock without any running process holding it. So primary use of SM12 is to know lock details and numer of total locks.

Regards

Clemens