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

regarding lock objects

Former Member
0 Likes
2,833

hello everyone,

plz tell me what's the use of lock objects and how we can create lock object in se11.

8 REPLIES 8
Read only

Former Member
0 Likes
1,594

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.

Here is a Link with good example

Look the following Links for additionl info.

http://help.sap.com/saphelp_nw04/helpdata/en/c2/2d7037ecc92a7ee10000009b38f8cf/content.htm

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

http://articles.techrepublic.com.com/5100-6329_11-5066352.html

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

http://help.sap.com/saphelp_nw04/helpdata/en/af/22ab01dd0b11d1952000a0c929b3c3/frameset.htm

http://help.sap.com/saphelp_nw04/helpdata/en/a2/3547360f2ea61fe10000009b38f839/frameset.htm

Function modules required for lock objects:

http://help.sap.com/saphelp_nw04/helpdata/en/af/22ab01dd0b11d1952000a0c929b3c3/frameset.htm

Hope this Helps

Read only

Former Member
0 Likes
1,594

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

GO TO SE11

Select the radio button "Lock object"..

Give the name starts with EZ or EY..

Example: EYTEST

Press Create button..

Give the short description..

Example: Lock object for table ZTABLE..

In the tables tab..Give the table name..

Example: ZTABLE

Save and generate..

Your lock object is now created..You can see the LOCK MODULES..

In the menu ..GOTO -> LOCK MODULES..There you can see the ENQUEUE and DEQUEUE function

Lock objects:

http://www.sap-img.com/abap/type-and-uses-of-lock-objects-in-sap.htm

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

Match Code Objects:

http://help.sap.com/saphelp_nw2004s/helpdata/en/41/f6b237fec48c67e10000009b38f8cf/content.htm

http://searchsap.techtarget.com/tip/0,289483,sid21_gci553386,00.html

See this link:

http://www.sap-img.com/abap/type-and-uses-of-lock-objects-in-sap.htm

Check these links -

Read only

Former Member
0 Likes
1,594

Hi,

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.

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.

8> Choose Activate.

Result

When you activate the lock object, the two function modules

ENQUEUE_<lockobjectname> and DEQUEUE_<lockobjectname>

are generated from its definition to set and release locks.

Regards,Priya.

Read only

Former Member
0 Likes
1,594

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.

&----


*& Report ZLOCKING *

*& *

&----


*& *

*& *

&----


REPORT zlocking .

DATA : tab_emp TYPE TABLE OF zemp_51772,

wa_emp TYPE zemp_51772.

wa_emp-emp_no = '102'.

wa_emp-emp_id = '157'.

wa_emp-emp_name = 'SIVA'.

wa_emp-emp_dept = 'SAP'.

APPEND wa_emp TO tab_emp.

CLEAR wa_emp.

wa_emp-emp_no = '128'.

wa_emp-emp_id = '138'.

wa_emp-emp_name = 'RAMA'.

wa_emp-emp_dept = 'SAP'.

APPEND wa_emp TO tab_emp.

CLEAR wa_emp.

wa_emp-emp_no = '133'.

wa_emp-emp_id = '121'.

wa_emp-emp_name = 'KRISHNA'.

wa_emp-emp_dept = 'SAP'.

APPEND wa_emp TO tab_emp.

CLEAR wa_emp.

CALL FUNCTION 'ENQUEUE_E_TABLEE'

EXPORTING

mode_rstable = 'X'

tabname = 'ZEMP_51772'

  • varkey =

  • X_TABNAME = ' '

  • X_VARKEY = ' '

  • _SCOPE = '2'

  • _WAIT = ' '

  • _COLLECT = ' '

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3

.

IF sy-subrc EQ 0.

INSERT zemp_51772 FROM TABLE tab_emp.

ENDIF.

CALL FUNCTION 'DEQUEUE_E_TABLEE'

EXPORTING

mode_rstable = 'X'

tabname = 'ZEMP_51772'

  • VARKEY =

  • X_TABNAME = ' '

  • X_VARKEY = ' '

  • _SCOPE = '3'

  • _SYNCHRON = ' '

  • _COLLECT = ' '

.

IF sy-subrc EQ 0.

WRITE:/ 'Unlocked the Table'.

ENDIF.

this gives u a basic idea.

Award if helpful

Thanks & Regards,

Sravani

Read only

Former Member
0 Likes
1,594

Hi

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

Enter lock object name beginning with EY or EZ

and hit create.

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

Enter short text /tbale/lockmode.

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’.

If another user (say abap2) tries to access the same data i.e. matnr = ‘000000000000000012’,via a program or a transaction it would deny him read or write access.

Read only

Former Member
0 Likes
1,594

Hai,

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 (see Function Modules for Lock Requests). 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 (see also Conditions for Foreign Keys).

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.

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 position table.

Locks can also be set from programs in other systems with the corresponding interfaces if the lock object was defined with RFC authorization.

A lock mode can be assigned for each table in the lock object. This mode defines how other users can access a locked record of the table.

Table SFLIGHT in the flight model contains all the scheduled flights of a carrier. Field SEATSMAX contains the number of seats available. Field SEATSOCC contains the number of seats already booked. If a booking is made for a customer (by a travel agency or sales desk), you must check whether there are enough seats available. The number of seats booked is incremented when the booking is made.

This mechanism must ensure that two sales desks do not make the same booking at the same time and that the flight is not overbooked.

This can be done by creating lock object ESFLIGHT. Only the table SFLIGHT must be included in this lock object. The flight can then be locked (with the function modules generated from the lock object) when booking. If another sales desk also wants to book seats for this flight, the lock will prevent the flight from being overbooked.

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.

Activating a lock object in the ABAP Dictionary automatically creates function modules for setting (ENQUEUE_<lock object name>) and releasing (DEQUEUE_<lock object name>) locks.

The generated function modules are automatically assigned to function groups. You should not change these function modules and their assignment to function groups since the function modules are generated again each time the lock object is activated.

Never transport the function groups, which contain the automatically generated function modules. The generated function modules of a lock object could reside in a different function group in the target system. Always transport the lock objects. When a lock object is activated in the target system, the function modules are generated again and correctly assigned to function groups.

Parameters of the Function Modules

Field Names of the Lock Object

The keys to be locked must be passed here.

A further parameter X_<field> that defines the lock behavior when the initial value is passed exists for every lock field <field>. If the initial value is assigned to <field> and X_<field>, then a generic lock is initialized with respect to <field>. If <field> is assigned the initial value and X_<field> is defined as X, the lock is set with exactly the initial value of <field>.

Parameters for Passing Locks to the Update Program

A lock is generally removed at the end of the transaction or when the corresponding DEQUEUE function module is called. However, this is not the case if the transaction has called update routines. In this case a parameter must check that the lock has been removed.

Parameter _SCOPE controls how the lock or lock release is passed to the update program (see The Owner Concept for Locks). You have the following options:

_SCOPE = 1: Locks and lock releases are not passed to the update program. The lock is removed when the transaction is ended.

_SCOPE = 2: The lock or lock release is passed to the update program. The update program is responsible for removing the lock. The interactive program with which the lock was requested no longer has an influence on the lock behavior. This is the standard setting for the ENQUEUE function module.

_SCOPE = 3: The lock or lock release is also passed to the update program. The lock must be removed in both the interactive program and in the update program. This is the standard setting for the DEQUEUE function module.

Parameters for Lock Mode

A parameter MODE_<TAB> exists for each base table TAB of the lock object. The lock mode for this base table can be set dynamically with this parameter. Valid values for this parameter are S (shared), E (exclusive) and X (exclusive but not cumulative).

The lock mode specified when the lock object for the table is created is the default value for this parameter. This default value can however be overridden as required when the function module is called.

If a lock set with a lock mode is to be removed by calling the DEQUEUE function module, this call must have the same value for the parameter MODE_<TAB>.

Controlling Lock Transmission

Parameter _COLLECT controls whether the lock request or lock release should be performed directly or whether it should first be written to the local lock container. This parameter can have the following values:

Initial value: The lock request or lock release is sent directly to the lock server.

X : The lock request or lock release is placed in the local lock container. The lock requests and lock releases collected in this lock container can then be sent to the lock server at a later time as a group by calling the function module FLUSH_ENQUEUE.

Behavior for Lock Conflicts (ENQUEUE only)

The ENQUEUE function module also has the parameter _WAIT. This parameter determines the lock behavior when there is a lock conflict.

You have the following options:

Initial value: If a lock attempt fails because there is a competing lock, the exception FOREIGN_LOCK is triggered.

X : If a lock attempt fails because there is a competing lock, the lock attempt is repeated after waiting for a certain time. The exception FOREIGN_LOCK is triggered only if a certain time limit has elapsed since the first lock attempt. The waiting time and the time limit are defined by profile parameters.

Controlling Deletion of the Lock Entry (DEQUEUE only)

The DEQUEUE function module also has the parameter _SYNCHRON.

If X is passed, the DEQUEUE function waits until the entry has been removed from the lock table. Otherwise it is deleted asynchronously, that is, if the lock table of the system is read directly after the lock is removed, the entry in the lock table may still exist.

Exceptions of the ENQUEUE Function Module

FOREIGN_LOCK: A competing lock already exists. You can find out the name of the user holding the lock by looking at system variable SY-MSGV1.

SYSTEM_FAILURE: This exception is triggered when the lock server reports that a problem occurred while setting the lock. In this case, the lock could not be set.

If the exceptions are not processed by the calling program itself, appropriate messages are issued for all exceptions.

Reference Fields for RFC-Enabled Lock Objects

The type of an RFC-enabled function module must be completely defined. The parameters of the generated function module therefore have the following reference fields for RFC-enabled lock objects:

Parameters

Reference fields

X_<field name>

DDENQ_LIKE-XPARFLAG

_WAIT

DDENQ_LIKE-WAITFLAG

_SCOPE

DDENQ_LIKE-SCOPE

_SYNCHRON

DDENQ_LIKE-SYNCHRON

Read only

Former Member
0 Likes
1,594

hi,

You set a lock entry by calling an ENQUEUE function module for an appropriate lock object. You can

find out which lock objects are available for a database table from the table's where-used list in the

ABAP Dictionary. The "lock" and "unlock" function modules for the selected lock object require only the

ENQUEUE_<Name of lock object> and DEQUEUE_<Name of lock object> naming conventions. In

general, you need only pass the interface key fields. Default values are passed to all the other

parameters.

CALL FUNCTION 'ENQUEUE_ESSPFLI'

EXPORTING carrid = wa_spfli-carrid

connid = wa_spfli-connid

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.

Hope this helps, Do reward.

Read only

Former Member
0 Likes
1,594

Hi,

*LOCK OBJECTS:*

Lock Objects are used to synchronize access to the same data by more than one user

*Creation of lock objects:*

1. Go to SE11

2. Seelct Lock object

3. Give name of the lock object which Starts with EZ____

4. Create the object

5. Give short text

6. Under Tables-- primary key--selcetion mode

7. lock mode.

8. Enter the table name fields to be locked

9. Save, activate it.

Regards,

kavitha.