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
3,589

Define Lock Objects & Explain where they will be used?

10 REPLIES 10
Read only

Former Member
0 Likes
1,913

Hai.

check this.

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.

check this link for example.

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

tables:vbak.

call function 'ENQUEUE_EZLOCK3'

exporting

mode_vbak = 'E'

mandt = sy-mandt

vbeln = vbak-vbeln

  • X_VBELN = ' '

  • _SCOPE = '2'

  • _WAIT = ' '

  • _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.

Normally ABAPers will create the Lock objects, because we know when to lock and how to lock and where to lock the Object then after completing our updations we unlock the Objects in the Tables

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

purpose: If multiple user try to access a database object, inconsistency may occer. To avoid that inconsistency and to let multiple user give the accessibility of the database objects the locking mechanism is used.

Steps: first we create a loc object in se11 . Suppose for a table mara. It will create two functional module.:

1. enque_lockobject

1. deque_lockobject

before updating any table first we lock the table by calling enque_lockobject fm and then after updating we release the lock by deque_lockobject.

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 -

Regards.

Sowjanya.b.

Read only

Former Member
0 Likes
1,913

hi,

In addition to the basic objects, the following object classes are used in the SAP system:

Views

Matchcodes

Lock objects

Lock objects:simultaneous access to the same data by several users needs to be synchronized.

Simultaneous accessing of the same data record by two users in the SAP system is synchronized by a lock mechanism. When dialog transactions are programmed, locks are set and released by calling certain function modules. These function modules are generated automatically from the definition of so-called lock objects in the ABAP/4 Dictionary.

To synchronize the access to a table by setting and removing locks, a Lock object has to be defined in the ABAP/4 Dictionary. Activating the lock object automatically creates function modules for setting and removing locks. These function modules must be included when programming interactive transactions.

The steps involved in creating a lock object are the following:

1.Defining lock object attributes

2.Selecting secondary tables for the lock object

3.Selecting lock arguments and lock mode

4.Activating a lock object

reward if its useful

Read only

Former Member
0 Likes
1,913

Lock Objects:

Lock objects are used to synchronize access to the same data by more than one program.

Purpose:

The SAP system is equipped with a special lock mechanism that synchronizes access to data on the database. The purpose of the lock mechanism is to prevent two transactions from changing the same data on the database simultaneously .

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

Reward Points if useful.

Read only

Former Member
0 Likes
1,913

Lock Objects are Created using Tcode SE11.

The Lock object name must be start with EZur name.

Mainly lock objects are used for locking the transactions, tables --etec.

Multiple users can not updated the same transaction at the same time.

Whenever u create a lock object using se11. SAP internally

creates a two function modules:

Enqueue_lockobjname ---For Locking purpose,

dequeue_lockobjname---For Unlocking purpose.

U make use of these fms to lock and unlock transctions, tables..etc.

The example is as follws:


EPORT ZLOCK_UNLOCK
MESSAGE-ID ZBDC.

TABLES ZSTUD.

DATA text(8) TYPE c.

CALL SCREEN 100.

&---------------------------------------------------------------------
*& Module USER_COMMAND_0100 INPUT
&---------------------------------------------------------------------

text 
----------------------------------------------------------------------
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'SELECT'.
SELECT SINGLE * FROM ZSTUD WHERE ROLLNO = ZSTUD-ROLLNO.
MESSAGE i004 WITH 'SY-SUBRC:' sy-subrc.

WHEN 'EXIT'.
LEAVE PROGRAM.

WHEN 'ENQUEUE'.
CALL FUNCTION 'ENQUEUE_EZLOCK1'
EXPORTING
MODE_ZSTUD = 'X'
ROLLNO = ZSTUD-ROLLNO
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS = 3.

CASE sy-subrc.
WHEN 0.
MESSAGE i004 WITH 'Enqueue successful'(001).
WHEN 1.
text = sy-msgv1.
MESSAGE e004 WITH 'Record already'(002) 'locked by'(003)
text.
CALL TRANSACTION 'SM12'.
WHEN 2 OR 3.
MESSAGE e004 WITH 'Error in enqueue!'(004)
'SY-SUBRC:' sy-subrc.
ENDCASE.

WHEN 'DEQUEUE'.
CALL FUNCTION 'DEQUEUE_EZLOCK1'
EXPORTING
MODE_ZSTUD = 'X'
ROLLNO = ZSTUD-ROLLNO
EXCEPTIONS
OTHERS = 1.
CASE sy-subrc.
WHEN 0.
MESSAGE i004 WITH 'Dequeue successful'(005).
WHEN 1.
MESSAGE e004 WITH 'Error in dequeue!'(006).
ENDCASE.

WHEN 'SM12'.
CALL TRANSACTION 'SM12'.
ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT
&---------------------------------------------------------------------
*& Module STATUS_0100 OUTPUT
&---------------------------------------------------------------------

text 
----------------------------------------------------------------------
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'BASIC'.

ENDMODULE. " STATUS_0100 OUTPUT

Reward Points if useful

Read only

Former Member
0 Likes
1,913

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

Read only

Former Member
0 Likes
1,913

hi,

Locks are maintained in a central lock table. This ensures that also programs that run on a different

application server of the same SAP System, are informed of the locks.

Before a database update is triggered, the program requests a lock using a special function module. You

can set a lock for a data record in a database table, or even a set of records, according to you

requirements. The function module first checks whether there is an existing lock that will obstruct the

lock request. If a lock does not already exist then the lock is set.

If another program tries to set the same lock, the function module sends a message to say that the

record is already locked. This is carried out using an exception of the function module. Afterwards the

return code is set to the value <> 0.

The return code must be supplied with values in the program. You can inform the user of a corresponding message.

If the database change is successful, then the lock entry in the central lock table is deleted using a

different function module.

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.

Hope this helps, Do reward.

Read only

Former Member
0 Likes
1,913

Hi,

here is the simple answer for your Q.

lock objetcs are used for locking purpose. it mean suppose one user has open transaction code "XD02" for changing the customer 'X'. at the same time another user also want to change the same customer 'X' in this case second user should not allow for change. this can be done through locking mechanism.

suppose if you create a lock object through SE11, named as 'EIQMEL' then two function modules will create by system automatically named as 'ENQUEUE_EIQMEL' and 'DEQUEUE_EIQMEL'. so user has to call these two FM's in the program for locking and unlocking.

reward if helpful.

Regards

Venkat

Read only

Former Member
0 Likes
1,913

here u can get all you need to know about lock objects

http://www.stephan-brumme.com/download/erp/Assignment4.pdf - Similar pages

DO REWARD IF HELPFUL

Read only

Former Member
0 Likes
1,913

Hi,

To maintain the operational integrity lock objects are used.

If first person is modifying the record, and the other person is deleting the same record at the same time, then the first person gets a problem. To go away from such problems, sap has provided a locking mechanism.

If lock object is created in se11, Then internally two function modules are created . The two function modules are enque_lockobjectname and deque_lockobjectname.

Enqueue function module is used to lock the record in the program and deque function module is used to release the lock.

The record is locked at runtime.

regards,

kamala.

Read only

Former Member
0 Likes
1,913

Hi,

Kindly check this link.

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

This will help u.

Regards,

Thasneem