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

Lock objects??

Former Member
0 Likes
2,532

What is lock objects ?? Can anyone give me explanation..

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,416

<b>Lock objects</b> are use in SAP to avoid the inconsistancy at the time of data is being insert/change into database.

SAP Provide three type of Lock objects.

- Read Lock(Shared Locked)

protects read access to an object. The read lock allows other transactions read access but not write access to

the locked area of the table

- Write Lock(exclusive lock)

protects write access to an object. The write lock allows other transactions neither read nor write access to

the locked area of the table.

- Enhanced write lock (exclusive lock without cumulating)

works like a write lock except that the enhanced write lock also protects from further accesses from the

same transaction.

You can create a lock on a object of SAP thorugh transaction SE11 and enter any meaningful name start with EZ Example EZTEST_LOCK.

Use: you can see in almost all transaction when you are open an object in Change mode SAP could not allow to any other user to open the same object in change mode.

Example: in HR when we are enter a personal number in master data maintainance screen SAP can't allow to any other user to use same personal number for changes.

Technicaly:

When you create a lock object System automatically creat two function module.

1. ENQUEUE_<Lockobject name>. to insert the object in a queue.

2. DEQUEUE_<Lockobject name>. To remove the object is being queued through above FM.

You have to use these function module in your program.

Check this link.

http://help.sap.com/saphelp_nw70/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm

Regards,

Maha

6 REPLIES 6
Read only

former_member188829
Active Contributor
0 Likes
1,416

Hi,

Check this..

Read only

Former Member
0 Likes
1,417

<b>Lock objects</b> are use in SAP to avoid the inconsistancy at the time of data is being insert/change into database.

SAP Provide three type of Lock objects.

- Read Lock(Shared Locked)

protects read access to an object. The read lock allows other transactions read access but not write access to

the locked area of the table

- Write Lock(exclusive lock)

protects write access to an object. The write lock allows other transactions neither read nor write access to

the locked area of the table.

- Enhanced write lock (exclusive lock without cumulating)

works like a write lock except that the enhanced write lock also protects from further accesses from the

same transaction.

You can create a lock on a object of SAP thorugh transaction SE11 and enter any meaningful name start with EZ Example EZTEST_LOCK.

Use: you can see in almost all transaction when you are open an object in Change mode SAP could not allow to any other user to open the same object in change mode.

Example: in HR when we are enter a personal number in master data maintainance screen SAP can't allow to any other user to use same personal number for changes.

Technicaly:

When you create a lock object System automatically creat two function module.

1. ENQUEUE_<Lockobject name>. to insert the object in a queue.

2. DEQUEUE_<Lockobject name>. To remove the object is being queued through above FM.

You have to use these function module in your program.

Check this link.

http://help.sap.com/saphelp_nw70/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm

Regards,

Maha

Read only

Former Member
0 Likes
1,416

Hi

Lock Objects

Lock object concept

Lock modes

Creating a lock object (example)

Lock object sample code

SAP data dictionary provides you with a locking mechanism to synchronize simultaneous data access by different users.

Lock objects are created in SE11.

Customer lock objects must begin with EY or EZ .

Three possible lock modes exist for lock objects.

Lock Mode

Lock mode E: This sets a lock for changing data for single user. This lock can be accumulated.

Lock mode X: This mode is used like mode E for changing data. The only technical difference from mode E is that the respective lock does not allow accumulation.

Lock mode S: This mode ensures that data displayed in your program cannot be changed by other users during the entire display time. Here you do not want to change the data yourself (allows read only access for data).

Creating Lock object

SE11

1)Enter lock object name beginning with EY or EZ

and hit create.

2)Enter table names containing data records that should be locked and the lock mode.

Enter short text /tbale/lockmode.

3) The primary keys of the specified tables are automatically selected as lock parameters.

It automatically selects the primary key for the selected table.

To set a lock in the application program

call a function module ENQUEUE_<LOCK_OBJECT>.

For our example, it would be ENQUEUE_EZMARA.

To release the lock in the application program

call a function module DEQUEUE_<LOCK_OBJECT>.

For our example, it would be DEQUEUE_EZMARA.

Refer the code executed by user (say abap1) for

matnr = ’000000000000000012’.

Lock Objects are used to synchronize access to the same data by more than one user. Function modules that can be used in application programs are generated from the definition of a lock object in the ABAP Dictionary.

The R/3 System synchronizes simultaneous access of several users to the same data records with a lock mechanism. When interactive transactions are programmed, locks are set and released by calling function modules .These function modules are automatically generated from the definition of lock objects in the ABAP Dictionary.

Structure of a Lock Object

The tables in which data records should be locked with a lock request are defined in a lock object together with their key fields.

When tables are selected, one table (the primary table) is first selected. Further tables (secondary tables) can also be added using foreign key relationships.

Lock Arguments

The lock argument of a table in the lock object consists of the key fields of the table.

The lock argument fields of a lock object are used as input parameters in the function modules for setting and removing locks generated from the lock object definition. When these function modules are called, the table rows to be locked or

unlocked are specified by defining certain values in these fields.These values can also be generic. The lock argument fields therefore define which subset of the table rows should be locked

.

Data Dictionary/ Lock Objects

The simplest case of a lock object consists of exactly one table and the lock argument of the table is the primary key of this table. Several tables can also be included in a lock object. A lock request therefore can lock an entire logical

object, and not only a record of a table. Such a logical object can be for example a document comprising an entry in a header table and N entries in a positiontable.

Lock Mode

The lock mode controls whether several users can access data records at the same time. The lock mode can be assigned separately for each table in the lock object. When the lock is set, the corresponding lock entry is stored in the

lock table of the system for each table. Access by more than one user can be synchronized in the

following ways:

Exclusive lock: The locked data can only be displayed or

edited by a single user. A request for another exclusive lock

or for a

shared lock is rejected.

Shared lock: More than one user can access the locked data

at the same time in display mode. A request for another

shared lock is accepted, even if it comes from another user. An exclusive lock

is rejected. Exclusive but not cumulative: Exclusive locks can be requested

several times from the same transaction and are processed

successively. In contrast, exclusive but not cumulative locks

can be called only once from the same transaction. All other

lock requests are rejected.

1) Select object type Lock object in the initial screen of the ABAP Dictionary, enter an object name and choose Create. The name of a lock object should begin with an E (Enqueue).The maintenance screen for lock objects is displayed.

2) Enter an explanatory short text in the field Short text. You can then use the short text to find the lock object at a later time, for example with the R/3 Repository Information System.

3) Enter the name of the primary table of the lock object. All other tables in the lock object must be linked with the primary table using foreign keys.

4) Select the lock mode of the primary table in the field below it The lock mode is used as the default value for the corresponding parameters of the function modules generated from the lock object.

5) Choose Add if you want to lock records in more than one

table with the lock object. A list of all the tables linked with the primary table using valid foreign keys is displayed. Select the appropriate table. The lock

mode of the primary table is copied as lock mode. You can change this setting as required, for example you can assign the lock mode separately for each table.

Similarly, you can add a table linked with the secondary table just added with foreign keys. To do this, place the cursor on the name of the secondary table and choose Add.

If no lock mode is assigned to a table, no lock is set for the

entries in this table when the generated function modules are

called. You should not assign a lock mode if a secondary table

was only used to define a path between the primary table and

another secondary table with foreign keys.

6) Save your entries.

A dialog box appears in which you have to assign the lock

object a development class.

7) You can define whether the function modules generated from

the lock object should be RFC-enabled on the Attributes tab

page. If you set the Allow RFC flag, the generated function

modules can be called from within another system with Remote

Function Call. If you permit Remote Function Calls for an

existing lock object, you must ensure that the generated

function modules are called from within an ABAP program with

parameters appropriate for the type. You should therefore check

all programs that use the associated function modules before

activating the lock object with the new option.

😎 Choose Activate

Reward if u sefull

Read only

Former Member
0 Likes
1,416

A repository object defined in the ABAP Dictionary that serves as the basis for SAP locks. Linked database tables to which a common lock is to be applied are specified in a lock object using foreign key relationships. When a lock object is created, two lock function modules are automatically generated.

Special function module for setting and removing SAP locks. To create a lock object, a function module with the prefix ENQUEUE_ is created to set the lock and a function module with the prefix DEQUEUE_ is created to remove the lock.

A lock object is a virtual link of several SAP tables which is used to synchronize simultaneous access by two users to the same set of data ( SAP lock concept).

Locks are requested and released in the programming of online transactions by calling certain function modules which are automatically generated from the definition of the lock objects. These lock objects must be explicitly created in the ABAP Dictionary.

To set locks, you must perform the following steps:

1. You must define a lock object in the ABAP Dictionary. The name of the lock object should begin with E.

2. The function modules for requesting and releasing locks which are created automatically when the lock object is activated must be linked to the programming of the relevant online transactions.

Go to SE11

select Lock object

Give name it shoud start with E-> Create

Give Description -> give Primary Table name on which you want to set Lock

Select Mode of Lock- (Already Describe above)

use same lock name in ur module pool programing

in PBO

Call function ENQUEUE_Lockobject name

and before leave projram relese lock by calling function DEQUEUE_ Lockobject name

betwwen this two FM you do your DB operation.

This will help you.

Regards,

Hetal.

Read only

Former Member
0 Likes
1,416

hi,

Lock objects are use in SAP to avoid the inconsistancy at the time of data is being insert/change into database.

SAP Provide three type of Lock objects.

- Read Lock(Shared Locked)

protects read access to an object. The read lock allows other transactions read access but not write access to

the locked area of the table

- Write Lock(exclusive lock)

protects write access to an object. The write lock allows other transactions neither read nor write access to

the locked area of the table.

- Enhanced write lock (exclusive lock without cumulating)

works like a write lock except that the enhanced write lock also protects from further accesses from the

same transaction.

You can create a lock on a object of SAP thorugh transaction SE11 and enter any meaningful name start with EZ Example EZTEST_LOCK.

Use: you can see in almost all transaction when you are open an object in Change mode SAP could not allow to any other user to open the same object in change mode.

Example: in HR when we are enter a personal number in master data maintainance screen SAP can't allow to any other user to use same personal number for changes.

Technicaly:

When you create a lock object System automatically creat two function module.

1. ENQUEUE_<Lockobject name>. to insert the object in a queue.

2. DEQUEUE_<Lockobject name>. To remove the object is being queued through above FM.

You have to use these function module in your program.

Hope this will give a basic idea.

Read only

Former Member
0 Likes
1,416

Hi,

Lock Objects:

In SAP Locking Mechanism is used to restrict simultaneous updation of the same data. This is made possible with the help of Lock Objects. A list of key fields of a table are used for the same thus forming Lock Argument. This can also contain fields of more than one table, through Foreign Key relation. They are used in Function Modules when they are programmed.

There are different types of locks.

1. Shared lock

2. Exclusive lock

3. Exclusive but not cumulative lock

4. Optimistic lock

For further information you can refer to the links given below.

http://help.sap.com/saphelp_nw70/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm

http://help.sap.com/saphelp_nw04/helpdata/en/7b/f9813712f7434be10000009b38f8cf/content.htm

http://help.sap.com/saphelp_nw70/helpdata/en/af/22ab01dd0b11d1952000a0c929b3c3/content.htm

Cheers!!!

Rajesh.

P.S: Kindly Award points if found useful.