2014 Dec 11 2:25 PM
Hi guys,
i have an issue with OL (Local Object - transaction REBDRO):
I want modify document also if another user is in modify of document.
so I implemented this:
READ TABLE room_oaol INDEX 1.
wa_part1 = 'IM'.
wa_part2 = room_oaol-bukrs.
wa_part3 = room_oaol-swenr.
CONCATENATE room_oaol-bukrs wa_part3 room_oaol-smenr
INTO result RESPECTING BLANKS.
MOVE result TO wa_part4.
CALL FUNCTION 'DEQUEUE_EVICAGENERIC'
EXPORTING
mode_reca_enqueue_data = 'X'
* mandt = sy-mandt
part1 = wa_part1
part2 = wa_part2
part3 = wa_part3
part4 = wa_part4
x_part1 = abap_true
x_part2 = abap_true
x_part3 = abap_true
x_part4 = abap_true
_scope = '3'
_synchron = abap_false
_collect = abap_false
.
....
CALL FUNCTION 'BAPI_RE_RO_CHANGE'
EXPORTING
compcode = wa_room_oaol-bukrs
businessentitynumber = wa_room_oaol-swenr
rentalobjectnumber = wa_room_oaol-smenr
TABLES
arch_rel = tb_arch_relc
return = tb_return.
....
CALL FUNCTION 'ENQUEUE_EVICAGENERIC'
EXPORTING
mode_reca_enqueue_data = 'X'
* mandt = sy-mandt
part1 = wa_part1
part2 = wa_part2
part3 = wa_part3
part4 = wa_part4
x_part1 = abap_true
x_part2 = abap_false
x_part3 = abap_false
x_part4 = abap_false
_scope = '2'
_wait = abap_false
_collect = abap_false
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
but the 'BAPI_RE_RO_CHANGE' say me that the document is lock!
why? I used dequeue function!
2014 Dec 11 2:38 PM
Well, using DEQUEUE FM you revoked your own lock, not the locks of other users (they wouldn't be very happy you know)
Read some document as
The SAP Lock Concept (BC-CST-EQ), SAP Lock Concept, Example: Using the Check Lock Modes and Frequently Asked Questions: Lock Concept. For more information, see: Lock Owners and Function Modules for Lock Requests.
Then change your code
I want modify document also if another user is in modify of document.
Is against rules to preserve database consistencies and is not a legitimate solution, and is not an actual requirement.
Regards,
Raymond
2014 Dec 11 3:03 PM
excuse I explained bad
I want to edit the document while I am in editing the document (not another user).
So, document is locked by me (transaction REBDRO) AND my report can be modify the document.
So, the document is enqueued.
1. dequeued (unlock)
2. modify
3. enqueued (re-lock)
no?i'm worng?
2014 Dec 11 3:11 PM
Yes you are wrong. The lock concept is meant to prevent database inconsistencies NOT to delete a lock because you are using the same data in another program. Why you want to do that anyway is a complete mystery to me, but that is besides the case.
It ALWAYS is:
1. ENQUEUE
2. CHANGE DATA
3. DEQUEUE.
Again read the documentation and learn this properly because this is one of the most important parts you need to know as ABAP developer.
The links have been provided by Raymond.
2014 Dec 11 3:24 PM
I want modify the document with 'BAPI_RE_RO_CHANGE' WHILE I am in in editing the document.
So, I know that the document is enqueued! I don't need that if the document is enqueued.
I need to modify the document while I am in editing.
if I do enqueued it say me : document is locked ! I know that it is locked.
2014 Dec 11 3:47 PM
Did you analyze BAdI BADI_RE_BD_RO (If I did correctly identify the transaction?)
If no useful method in the BAdI interface, then analyze where the transaction stores the currently modified data, and if you find a “safe” solution to modify it.
Or if you don't need to keep the transaction running, just call a RFC enabled FM in BACKGROUND MODE (can be thru a PERFORM ON COMMIT)
So when user save the data, the transaction will execute a COMMIT WORK, update tasks will update the database and then your wrapper FM will execute when locks are released, so you can call BAPI and COMMIT in this FM executed in a new LUW.
NB: Using the BAPI during the transaction call will surely mess the data -> don’t (BAPI may/will reload data from database then update database and refresh some buffer, also commit may/will trigger some partial update prepared by trnasaction, don't even care to imagine the status of the calling transaction at this step...
Regards;
Raymond
2014 Dec 11 4:18 PM
I can't call my fm after save because i need update the data in real time.
2014 Dec 11 2:45 PM
You are implementing the lock concept in the wrong way.
You should use ENQUEUE first and when your finished updating you use the DEQUEUE FM.
Now when you leave the BAPI you are locking the database table. Why would you want to lock a database AFTER updates ? Study the lock concept in SAP Help because this is a very very very important part of ABAP programming.
When another user has locked the table (entries) the enqueue FM will give you this message. You can then either leave the program with a message or you can call the ENQUEUE in a WHILE LOOP.
pseudocode:
data: lv_subrc type sysubrc,
counter type i.
lv_subrc = 4.
while lv_subrc <> 0.
call FM enqueue
lv_subrc = sy-subrc.
if lv_subrc <> 0.
counter = counter + 1.
wait for X second. "X can be any amount of seconds, you decide how long this should be
endif.
if counter > 10. "try a maximum of 10 times
exit. "leave the while loop
endif.
endwhile.
* check if the queueing was succesfull
if lv_subrc <> 0.
message something
exit. or stop. or return. "depending on your programm structure
endif.
2014 Dec 11 3:04 PM
2014 Dec 11 3:23 PM
I want modify the document with 'BAPI_RE_RO_CHANGE' WHILE I am in in editing the document.
So, I know that the document is enqueued! I don't need that if the document is enqueued.
I need to modify the document while I am in editing.
if I click on button "associa OA ad OL" I want modify document through bapi...but the bapi say me that the document is locked.
So, I Dequeued document and after change document ! but it is wrong .
2014 Dec 11 3:33 PM
I don't think you can use the BAPI for that, you will need to use a user exit where the data to be changed is available to you, so you can adjust the instance that is already opened in the program. The BAPI wants to open the same instance again but since this is locked it gives an error.
Which user exit are you using now to call the BAPI ?
2014 Dec 11 3:47 PM
when you click on the button "associa OA ad OL" it open a browser.
through the browser you can access to another sistem (for example sistem SREMAP).
SAP --CALL--> SREMAP
On SREMAP You can see other information with OL in object.
When you stay on SREMAP you can modify the document.
So , when you modify the document FROM SREMAP it call web service (function on sap) where there is my bapi_change.
SREMAP --CALL--> SAP
but my bapi_change say me "the document is locked" , because I am in edit of the document.
I know that it is locked.
Now, I need to edit the document by SREMAP while I editing the document.
help me please , thanks
2014 Dec 12 9:16 AM
I solved the issue with:
CALL FUNCTION 'ENQUEUE_READ'
EXPORTING
gclient = sy-mandt
guname = sy-uname
gname = 'RECA_ENQUEUE_DATA'
garg = garg
IMPORTING
subrc = subrc
TABLES
enq = enq
EXCEPTIONS
communication_failure = 2
OTHERS = 1.
IF sy-subrc = 0.
CALL FUNCTION 'ENQUE_DELETE'
EXPORTING
check_upd_requests = 1
IMPORTING
subrc = subrc
TABLES
enq = enq.
REFRESH enq.
CLEAR enq.
ELSEIF sy-subrc = 2.
MESSAGE w116.
ENDIF.
2014 Dec 12 10:30 AM
And which data is now going to be saved to the database, the changes you made in the screen or the changes made by the BAPI ?
Did you try a test where you change something in the document FIRST and then click the button which calls this BAPI to see what happens ?
I would not feel comfortable with a solution that you have presented. It goes against the rules of safe programming. You should at least do lots of testing where you make changes in all possible ways to see if your solution can cause any confilcts when updating the database.