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

locks issue

Former Member
0 Likes
1,207

HI All

I have table that called by service (this process can take time since the table is full with data ) ,

the problem is that the table can be updated during the service read call which can cause inconsistency ,i read on the help about the read lock and exclusive lock i i think that i should use both of them but i am not sure ,

if i need to use both, how should i use it ?

before the select i use the read lock or before the update ?

or for the update process i should use both of the locks ..

any simple example will help .

Regards

JOy

1 ACCEPTED SOLUTION
Read only

Pawan_Kesari
Active Contributor
0 Likes
1,168

Basically you don't want anyone to modify the data when your service is reading it.

Putting a lock on data from service before reading it will prevernt any changes being made during the read process.

In update program you will have to make change (if it is not there already) so that it first request for lock and if request is successful then carry on changes.

12 REPLIES 12
Read only

Former Member
0 Likes
1,168

This message was moderated.

Read only

Former Member
0 Likes
1,168

HI

any idea?

Thanks

Read only

Pawan_Kesari
Active Contributor
0 Likes
1,169

Basically you don't want anyone to modify the data when your service is reading it.

Putting a lock on data from service before reading it will prevernt any changes being made during the read process.

In update program you will have to make change (if it is not there already) so that it first request for lock and if request is successful then carry on changes.

Read only

0 Likes
1,168

HI ,

basically what i need to use is Exclusive lock for update, multiple locks for the read process

but i need some simple example how i should use this both locks for the table

Thanks Joy

Edited by: Joy Stpr on Nov 2, 2009 2:00 PM

Read only

0 Likes
1,168
Read only

0 Likes
1,168

Hi Joy

I think u're speaking about SAP lock, this is a logical lock and not a database lock.

So it's not really important if the lock is Exclusive or Read, because u need to check the lock and then decide what to do if the lock is active.

After creating the lock by SE11, the system generates the fms in order to lock and unlock the lock.

Now the problem is u should place the control of the lock in the service and in all report can update your table.

Every report should abort the running if the lock is actve.

Do u really want to do this?

Max

Read only

0 Likes
1,168

Hi Max

Thanks

i have to do this .

there is scheduled job which update the table and can run for 1 hour (and can have 1000000 records ).

the web service is call to the table data with paging mechanism ( i.e. for 100 records in every service call ) the problem is if the service initiate a call and get 500 records and the update process is started ,this can cause to inconsistency so for that i need the locks mechanism .

my opinion is to do Exclusive lock for update, multiple locks for read.

but i am not sure about it since i am new to this topic .

in the update process do i need to lock all the table ?

since i update the table via

MOdify Z table from itab

and for read i call every time for 100 or 200 records (select upto 100/200 users ) how should i lock it ?

Thanks

Joy

Read only

0 Likes
1,168

Hi

U can create a lock object for your Z-TABLE by SE11, the name convention for the lock should be E<table name>: while activing it, the system generates 2 function module to lock and unlock, the function module will be called:

- ENQUEUE_<lock object> to set the lock

- DEQUEUE_<lock object> to delete the lock

In both your programs: web service and job u should call the fm to set the lock ENQUEUE_<lock object>, if this fm returns sy-subrc equal to 0, it means the lock is set else the lock is just set, in this last case u should decide what u need to do.

Case: A) Web service starts and it gets a lock active: I suppose u should stop the service because it means the job is running;

Case B) Job start and it gets a lock active: it means a web service is running, so probably u need to stop the job (?),

u could have a conflict situation if job is a priority higher than web service

U can use the fm DEQUEUE_<lock object> to delete the job, but u need to consider the lock is automatically deleted at the end of a task, so as soon as the job iand web service is finished.

Max

Read only

0 Likes
1,168

>

> there is scheduled job which update the table and can run for 1 hour (and can have 1000000 records ).

>

Based on number of records you are updating, I will not recommend to put lock for each record as it will possibly overflow the Lock table.

Read only

0 Likes
1,168

HI MAx

Thanks ,

in the update process do i need to lock all the table ?

since i update the table via

MOdify Z table from itab

the other option is to lock every record and modify it ,

what is your opinion ?

and for read i call every time for 100 or 200 records (select upto 100/200 users ) how should i lock it for every recored ?

Thanks again

joy

Edited by: Joy Stpr on Nov 3, 2009 8:38 AM

Read only

0 Likes
1,168

Hi,

During updation of a table you need to lock the record which you want to update.

Using the primary keys combination you can lock the record which you are updating.These key combinations should be passed as arguments to the lock function module .

Regards,

Lakshman.

Edited by: Lakshman N on Nov 4, 2009 6:26 AM

Read only

0 Likes
1,168

Hi

U need to lock the whole table and not a single record

Remember it's only a logic lock, so u can avoid a SQL updating, but u can check the result returned by fm to set the lock and decide what u need to do

Max