Locking of table record
Hi,
I want to lock particular table record when user click on Update button and unlock when user click on Save Changes button. So that if user updating any record other user should not able to update it.
For this i have used TableLocking's lock method with UserSession lifetime and stateless bean. Its working fine but if user click on update button and then without clicking on Save Changes button if he close the browser, obviously that record will not be unlock. I have to manually unlock that record in doExit method.
Am i doing it write or is there any easy way to do this?
I have also tried to use lifetime as Transaction so that record get unlock automatically as update query fired and its working but record also get unlock if any other query fired like insert or delete as Database tool internally automatically fire the commit command.
So plz suggest batter way to do locking?
Hi Vikram
I'm not sure if I could help you but what we have done in one of our projects is that we have used the enqueue/dequeueu mechanism when using rfc's. So for example:
1. One WebDynpro view where we read data from backend via a rfc call. In that process we do an enqueue so that the records that we read from backend are locked. (Note you can't do a disconnectIfAlive in this step because then the connection with the backend and the lock will be lost)
2. A second WebDynpro view where the user can update the data and save the data via another rfc call. Here we do an dequeue (if the data entered is validated ok) so that the records are unlocked. Here you must do a .disconnectIfAlive() so that the connection with backend is released.
Here is another thread discussing the same subject:
Regards
Göran
Similar Messages
-
How to lock a table/record from being read
Hi,
We are facing a problem executing a backend operation due to the presence of 2 JVMs.
We have a set of batch jobs that needs to run on a daily basis. We are using a flag in a table to check if any job is currently running, based on which the job is kicked off.
The problem comes up when the 2nd JVM tries to read the same data present in the table and kicks off the job, which it shouldnt.
Currently this is how i am implementing it:
SELECT COUNT(1) into l_status FROM Log_Table
where job_status is NULL
FOR UPDATE;
IF (l_status = 1) THEN
UPDATE Log_Table
SET Job_Status = 'In_Execution'
WHERE Job_status = NULL; -- Only 1 rec will contain this field as NULL
END IF;
COMMIT;
l_status decides whether the job should run or not.
SELECT..FOR UPDATE does not stop the 2nd JVM from reading the data (or will it?). The 2nd JVM will just wait for the lock to be released, execute the UPDATE without knowing the current value of Job_Status and then start the batch job. Correct me if my knowledge of SELECT FOR UPDATE is wrong.
What can be done to completely avoid the 2nd JVM from intervening?
Solutions would be much appreciated.I have dealed with your problem. Please checkout thread Is it possible to pevent select operation on a table?
-
How to find out which user has locked a particular record of a table
Hi
Is it possible to know - which user has locked a particular record (I know the primary key of the record) of a table
Regardsselect OS_USER_NAME os_user,
PROCESS os_pid,
ORACLE_USERNAME oracle_user,
l.SID oracle_id,
decode(TYPE,
'MR', 'Media Recovery',
'RT', 'Redo Thread',
'UN', 'User Name',
'TX', 'Transaction',
'TM', 'DML',
'UL', 'PL/SQL User Lock',
'DX', 'Distributed Xaction',
'CF', 'Control File',
'IS', 'Instance State',
'FS', 'File Set',
'IR', 'Instance Recovery',
'ST', 'Disk Space Transaction',
'TS', 'Temp Segment',
'IV', 'Library Cache Invalidation',
'LS', 'Log Start or Switch',
'RW', 'Row Wait',
'SQ', 'Sequence Number',
'TE', 'Extend Table',
'TT', 'Temp Table', type) lock_type,
decode(LMODE,
0, 'None',
1, 'Null',
2, 'Row-S (SS)',
3, 'Row-X (SX)',
4, 'Share',
5, 'S/Row-X (SSX)',
6, 'Exclusive', lmode) lock_held,
decode(REQUEST,
0, 'None',
1, 'Null',
2, 'Row-S (SS)',
3, 'Row-X (SX)',
4, 'Share',
5, 'S/Row-X (SSX)',
6, 'Exclusive', request) lock_requested,
decode(BLOCK,
0, 'Not Blocking',
1, 'Blocking',
2, 'Global', block) status,
OWNER,
OBJECT_NAME
from v$locked_object lo,
dba_objects do,
v$lock l
where lo.OBJECT_ID = do.OBJECT_ID
AND l.SID = lo.SESSION_ID
hope this helps
Zekeriya -
In an SAP Table is to possible to perfrom lock at the record level?
Hi All,
In an SAP Table/Ztable is to possible to perfrom lock at the record level?
Is it possible to increease the size of the sap table or z-table to insert more records.
For example I want to insert 50000 records into a z-table and the size category I have given as 0 means which can hold some 15thousand records.
then what abt the remaining recors?
how can I inser tthem?
do I need to increase the manually or it will be done automatically?
Could any one please explain this?
Thanks in Advance.
Regards.
Abhilash.hi,
u can insert no of records into table based on ur size category.
check these.
0 0 to 1,200
1 1,200 to 4,900
2 4,900 to 19,000
3 19,000 to 78,000
4 78,000 to 310,000
5 310,000 to 620,000
6 620,000 to 25,000,000
to lock records check this data.
Lock mode
Defines how to synchronize table record access by several users.
The following modes exist:
Exclusive lock
The locked data can be read or processed by one user only. A request for another exclusive lock or for a shared lock is rejected.
Shared lock
Several users can read the same data at the same time, but as soon as a user edits the data, a second user can no longer access this data. Requests for further shared locks are accepted, even if they are issued by different users, but exclusive locks are rejected.
Exclusive but not cumulative lock
Exclusive locks can be requested by the same transaction more than once and handled successively, but an exclusive but not cumulative lock can only be requested once by a given transaction. All other lock requests are rejected.
reward points if hlpful. -
How can we lock the table?? how can we lock the record
Hi
how can we lock the complete table?? how can we lock the record ?/
Thanks
RamaLock objects are used to lock the database table while making the modifications on the database table.
you can create your own lock objects using SE11.
if you create lock objects on any table system will create two function modules.
1.ENQUEUE....
2.DEQUEUE.....
first one is used to lock the table
second one used to removing lock on the table.
lock Table
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
tabname = table_name
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
Unlock Table
CALL FUNCTION 'DEQUEUE_E_TABLE'
EXPORTING
tabname = table_name
check this link :
http://help.sap.com/saphelp_40b/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm
_SCOPE = 1: The lock is not sent to the update program. The lock is removed when the transaction is ended.
_SCOPE = 2: The lock is sent to the update program. The update program is responsible for removing the lock. The dialog program which requested the lock no longer has an influence on the lock behavior. This is the standard setting for the ENQUEUE function module.
_SCOPE = 3: The lock
Re: lock objects
Reward if this helps. -
Lock Object (Not locking the table)
Hi Guys
I have a custom table ZDRAD same like standard table DRAD with an additional 'DATE' field . ZDRAD's Key fields are same like DRAD . I have created a lock object 'EZDRAD' where I put name = 'ZDRAD' (Custom table) and mode = 'EXCLUSIVE CUMULATIVE' . Now I want to lock the table(Whole table) before modifying/Inserting/deleting the records in se38. Please check the code below and suggest me if I am passing wrong values to the lock object Function module.
Code
TABLES : ZDRAD.
CALL FUNCTION 'ENQUEUE_EZDRAD'
EXPORTING
MODE_ZDRAD = 'E'
MANDT = SY-MANDT
DOKAR = ' '
DOKNR = ' '
DOKVR = ' '
DOKTL = ' '
DOKOB = ' '
OBZAE = 0
OBJKY = ' '
X_DOKAR = ' '
X_DOKNR = ' '
X_DOKVR = ' '
X_DOKTL = ' '
X_DOKOB = ' '
X_OBZAE = ' '
X_OBJKY = ' '
_SCOPE = '2'
_WAIT = 'X'
_COLLECT = ' '
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS = 3
*IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
IF SY-SUBRC = 0.
ZDRAD table is locked.
P_L_LOCK_STAT = 'X'.
EXIT.
ELSE.
ZDRAD table is not locked
CLEAR P_L_LOCK_STAT .
ENDIF.Hi Kanthimathi
That is numeric field . Please suggest me how can i check the lock. -
KP06 Cost Center Budget Planning System error when locking the data records
Hi,
While updating Cost Center Planning system(KP06) its giving the below error:
System error when locking the data records.
Message no. KI502
Diagnosis
The lock to protect the data records being processed could not be set. The
probable reason for this is that the SAP locking table is full and no more
entries can be added.
Procedure
Inform your system administrator immediately
No planning data has been changed
Message no. K8038
Diagnosis
You used Post. While preparing the data for posting, the SAP System
determined that no changes were made in the available databank values.
System Response
A posting activity price is not necessary
Please help me how can we rectify the above error..
Thanks
VS RaoHi,
check the locking entries (t-code SM12).
http://help.sap.com/saphelp_erp2004/helpdata/en/37/a2e3ae344411d3acb00000e83539c3/frameset.htm
Best regards, Christian -
I just wanted to know , how the lock works on a table. I am very much confused..
Let me put down my requirement...
I am inserting a new record in a Table(Batches) for which one of the columns(no_batch) is an incrementing value. To acheive this, I select the max value of the above column from the same table and add 1 to it.
(Pl note: I cannot use sequence for this
nor I cannot have an UNIQUE constraint on this Column... )
Then I insert this new Record.
The problem what i faced was...
When Multiple users accessed to insert the record at the same time,
Selecting and inserting on the table allowed duplicate values to be inserted on the no_batch column in the batches Table.
Is there any way out to lock the Table exclusively, when a user is accessing this Table until he/she gives a COMMIT or ROLLBACK operation on the Table.
so that the next user should wait for the Resources.
The Time delay is okay for me.
Here is the skeleton of my insert procedure..
PROCEDURE insert_record IS
BEGIN
<set of statements>
SELECT max(no_batch) + 1
into var_no_batch
from batches
where <conditions> ;
insert into batches values
(val1, val2, val3,var_no_batch,........);
commit;
END;
I have an alternative, but I dont know whether this will work out.
Can I give an UPDATE statement which will update 0 rows on the same Table, so that it will be locked, and then, I SELECT and INSERT on the same table, which I guess will work, and a COMMIT will release the LOCK on this Table..
Let me know if this is correct...
This is very urgent.....
Any help and suggestions would be greatly appreciated. and Thanks in Advance..
nullThanks for your Help and Suggestions...
Sorry,I cannot use a select for update Clause, since the select has an aggregate function.
There are some other procedures which access this Table(only select statements). Will this LOCK stop the other users also who access this Table through the SELECT procedures. Please let me know about that. -
ENQUEUE DEQUEUE FM's for updating VBAP table record
HI all,
I am updating records of vbap table. so i want to lock those records while am updatin them .
which FM's should i use to update them ?Thanks for ur replies Himanshu and Sayed,
I have already used these FM's. But i didnt feel like it is working. I went in debugging mode and executed ENQUEUE FM and the i went in VA02 transaction and for the same sales order i tried updaing the quantity and it is updated in the table.
How come this has happened even though i have locked the table with the help of FM. ?
I have used the FM something like this :
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
MODE_RSTABLE = 'E'
TABNAME = 'VBAP'
VARKEY = 'VBELN'
X_TABNAME = ' '
X_VARKEY = ' '
_SCOPE = '2'
_WAIT = ' '
_COLLECT = ' '
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS = 3
IF sy-subrc EQ 0.
UPDATE vbap FROM TABLE li_vbap.
CALL DEQUEUE.
ENDIF. -
I am a newbie in OAF.
We have a OAF page based on a table with some records. If a user click on update button for some record a new page is opened and his "USERNAME" goes to the "LOCKED_BY" column in that table. When user click the save button the records are updated and the lock is released by updating the "LOCKED_BY" column to null.
If another user tries to update the same record for which "LOCKED_BY" column is not null, He gets a message that the 'table is locked by some other user'.
Everything works fine but We need to release lock on this screen as soon as user close screen.
So please suggest me some other technique for locking the table.
Regards,
GauravPlease ask this in the {forum:id=210} forum!
Timo -
Hi,
I am writing program to upload data from excel to custom tables.
Here i add/ update/delete records from the table based on entries from excel sheet.
While i run this program, how do i maintain locks on the table, so that any other user is not modifying the tables at the same time.
Points will be awarded immediately.
Thanks<b>Lock objects</b> are used to lock the database table while making the modifications on the database table.
you can create your own lock objects using SE11.
if you create lock objects on any table system will create two function modules.
<b>1.ENQUEUE....
2.DEQUEUE.....</b>
first one is used to lock the table
second one used to removing lock on the table.
<b>This lock object</b> facilitates synchronous process. That is suppose if you are changing the table entries, and simultaneously there might be several programs running in the background or by anything else which also does changes to the same table. In this case you can lock the table so that other program will not able to update/insert/ do any other operation unless or until your program executes successfully.
You can create lock objects for this purpose in transaction SE11. SAP by default create 2 function modules. One for locking ( Enqueue) and other for unlocking ( Dequeue ). You can call these function module in appropriate places in your program.
ex...
lock Table
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
tabname = table_name
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
Unlock Table
CALL FUNCTION 'DEQUEUE_E_TABLE'
EXPORTING
tabname = table_name
<b><u>check the below links:</u></b>
http://help.sap.com/saphelp_40b/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm
Re: lock objects
Regards,
Moqeeth. -
How to see lock on table and query?
Hi All,
How do we see lock on table and query?
Thanks,
RafiYes Rafi,
It is working fine at my end. See below:
Opened Session 1 with scott/tiger and:
update emp set ename='xx' where empno=7499;
Opened Session 2 with scott/tiger and:
update emp set ename='xx' where empno=7499;
<<Its lock here>> This session is locked by above one.
Opened Session 3 with sys/pw as sysdba and:
SQL> set serveroutput on
SQL> BEGIN
2 dbms_output.enable(1000000);
3 for do_loop in (select session_id, a.object_id, xidsqn, oracle_username, b.owner owner,
4 b.object_name object_name, b.object_type object_type
5 FROM v$locked_object a, dba_objects b
6 WHERE xidsqn != 0
7 and b.object_id = a.object_id)
8 loop
9 dbms_output.put_line('.');
10 dbms_output.put_line('Blocking Session : '||do_loop.session_id);
11 dbms_output.put_line('Object (Owner/Name): '||do_loop.owner||'.'||do_loop.object_name);
12 dbms_output.put_line('Object Type : '||do_loop.object_type);
13 for next_loop in (select sid from v$lock
14 where id2 = do_loop.xidsqn
15 and sid != do_loop.session_id)
16 LOOP
17 dbms_output.put_line('Sessions being blocked : '||next_loop.sid);
18 end loop;
19 end loop;
20 END;
21 /
Blocking Session : 139
Object (Owner/Name): SCOTT.EMP
Object Type : TABLE
Sessions being blocked : 134
PL/SQL procedure successfully completed.HTH
Girish Sharma -
How can I convert table object into table record format?
I need to write a store procedure to convert table object into table record. The stored procedure will have a table object IN and then pass the data into another stored procedure with a table record IN. Data passed in may contain more than one record in the table object. Is there any example I can take a look? Thanks.
I'm afraid it's a bit labourious but here's an example.
I think it's a good idea to work with SQL objects rather than PL/SQL nested tables.
SQL> CREATE OR REPLACE TYPE emp_t AS OBJECT
2 (eno NUMBER(4)
3 , ename VARCHAR2(10)
4 , job VARCHAR2(9)
5 , mgr NUMBER(4)
6 , hiredate DATE
7 , sal NUMBER(7,2)
8 , comm NUMBER(7,2)
9 , deptno NUMBER(2));
10 /
Type created.
SQL> CREATE OR REPLACE TYPE staff_nt AS TABLE OF emp_t
2 /
Type created.
SQL> Now we've got some Types let's use them. I've only implemented this as one public procedure but you can see the principles in action.
SQL> CREATE OR REPLACE PACKAGE emp_utils AS
2 TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
3 PROCEDURE pop_emp (p_emps in staff_nt);
4 END emp_utils;
5 /
Package created.
SQL> CREATE OR REPLACE PACKAGE BODY emp_utils AS
2 FUNCTION emp_obj_to_rows (p_emps IN staff_nt) RETURN EmpCurTyp IS
3 rc EmpCurTyp;
4 BEGIN
5 OPEN rc FOR SELECT * FROM TABLE( CAST ( p_emps AS staff_nt ));
6 RETURN rc;
7 END emp_obj_to_rows;
8 PROCEDURE pop_emp (p_emps in staff_nt) is
9 e_rec emp%ROWTYPE;
10 l_emps EmpCurTyp;
11 BEGIN
12 l_emps := emp_obj_to_rows(p_emps);
13 FETCH l_emps INTO e_rec;
14 LOOP
15 EXIT WHEN l_emps%NOTFOUND;
16 INSERT INTO emp VALUES e_rec;
17 FETCH l_emps INTO e_rec;
18 END LOOP;
19 CLOSE l_emps;
20 END pop_emp;
21 END;
22 /
Package body created.
SQL>Looks good. Let's see it in action...
SQL> DECLARE
2 newbies staff_nt := staff_nt();
3 BEGIN
4 newbies.extend(2);
5 newbies(1) := emp_t(7777, 'APC', 'CODER', 7902, sysdate, 1700, null, 40);
6 newbies(2) := emp_t(7778, 'J RANDOM', 'HACKER', 7902, sysdate, 1800, null, 40);
7 emp_utils.pop_emp(newbies);
8 END;
9 /
PL/SQL procedure successfully completed.
SQL> SELECT * FROM emp WHERE deptno = 40
2 /
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
7777 APC CODER 7902 17-NOV-05 1700
40
7778 J RANDOM HACKER 7902 17-NOV-05 1800
40
SQL> Cheers, APC -
How can I lock a table so that a person can only enter data, not manipulate the table?
I don't want to Lock the table as Numbers does it so perhaps locking is the wrong term. What I want to do is to lock the formatting of the table so it is possible to enter data but not possible to change the position, number of columns etc. I've been searching and all I can come up with is the regular lock function. But I still want to be able to use the cells. Just not change formatting.
Thanks, Bradyou cannot. When you lock a table the whole table is locked. I would consider segmenting the user input into a seprate, un-locked table and placing the calculations in a locked table
-
Shell Script For Export And Import Of Table Records
Hello,
We have production and test instances and for constant testing we need to copy data from production to test or development environment.
At the moment what we do is manually doing export and import table records. At times this could be very tedious as we may need
to do this exercise a couple of times in a day.
Is it a good idea to do this exercise using shell script? If so how could I do this? If this is not a good idea what are the best alternatives?
Any input is highly appreciated.
ThanksAh I see, your company prefers stupidity over efficiency. It would be possible to do it in a controlled environment, wouldn't it? Also the test database would be allowed to select only.
So the non-allowance is just plain stupid.
To the second question: do you use hard-coded passwords in shell scripts?
Don't you think that poses a security risk?
Don't you think that is a bigger risk than a database link, properly set up?
In my book it is!
Sybrand Bakker
Senior Oracle DBA
Maybe you are looking for
-
FacesCtrlListBinding getInputValue ADFv: error while reactivating a reg
Jdev. 11.1.1.4 Trying to apply this in my application: http://one-size-doesnt-fit-all.blogspot.com.es/2011/06/jdev-111140-afshowdetailitems-and_20.html I'm getting this error while trying to programmatically reactivate my region after having deactiva
-
HT1040 iPhoto Book Order won't go through, can't get an answer
I have been all over Apple online help, FAQs, and online discussions on this topic and have not been able to get my book to print. The problem: when in iPhoto, I hit the Buy Book button, the white envelope appears. I enter the number of copies I want
-
Face time activation - an error occurred while verifying your email
i can't get facetime to work on my iPad - i go to settings add my account details and password (i know they are correct as i just logged onto my apple account and they worked fine) - and when i click on "next" the message that comes up is "an eror oc
-
My family wants to use my Powerbook (its screen is dying) in closed-lid mode with an external display. Is there any keyboard or other USB device with a power button that can start up my generation of Powerbook? 15" Powerbook G4 1.5 GHz Mac OS X (10
-
How do I see the number of songs i have in iTunes 11
In the old itunes it would be displayed in the grey bar along the bottom. How do we see it now?