2012 May 11 10:28 AM
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
2012 May 11 11:53 PM
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 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
2012 May 11 10:38 AM
"But the document is not open" - May be opened by some body else not at your location.
2012 May 11 10:44 AM
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.
2012 May 11 10:48 AM
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.
2012 May 11 10:55 AM
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
2012 May 11 11:14 AM
Then, sales document might already be locked in your RFC. Just try updating without using enqueue function.
Regards,
Sindhu Pulluru.
2012 May 11 11:56 AM
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
2012 May 11 1:19 PM
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.
2012 May 11 10:24 PM
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.
2012 May 11 11:53 PM
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
2012 May 14 6:46 AM
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
2012 May 14 4:25 PM
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
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |