Skip to Content
author's profile photo Former Member
Former Member

Lock Objects

Hi,

What is lock objects and give me some examples for lock objects…

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 31, 2008 at 03:43 AM

    Prasad,

    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

    lock-objects

    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

    Hope this Helps

    VB

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 31, 2008 at 03:36 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 31, 2008 at 03:37 AM

    Hi Prasad,

    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

    Plzz reward if it is useful,

    Mahi.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 31, 2008 at 06:16 AM

    Hi Prasad,

    In addition to above replys i would like to add some more information about lock objects . I hope it would be useful for you.

    The SAP R/3 system protects data if multiple users attempt to change it simultaneously. This guarantees data correctness and consistency even when a large number of users are connected to the SAP system. In a SAP environment, for example, only a single developer (session) can change the source code of an ABAP program at a time, and only one user is allowed to view the maintenance screen of a particular customizing table.

    What makes this all happen is an additional SAP locking mechanism that enables you to synchronize concurrent read or write requests for a particular set of data. The purpose is to prevent writing data that is being read by someone or restricting data from being read that is already in the editing mode.

    Lock objects

    Before applying locking in your programs, you must create lock objects for that particular set of data. You can create new lock objects or display (or change) existing ones via the standard ABAP Dictionary (SE11) transaction. Typical examples of lock objects are:

    E_TABLES&#65533;&#65533;&#65533; Shared Lock Object for Table Views

    ESRDIRE&#65533;&#65533;&#65533;&#65533;&#65533;&#65533; Lock Objects for ABAP/4 programs

    EPPRELE&#65533;&#65533;&#65533;&#65533;&#65533;&#65533; Lock Object for Employee Number Range

    Here, the lock conditions and lock modes are specified.

    Lock conditions (defined by lock parameters)

    While defining the lock object, you need to specify the field names that constitute the lock condition. The lock conditions depict the table fields you want to prevent from being concurrently accessed, usually key data that uniquely specifies a particular object or table entry. For example, if I wanted to lock the personnel number in a particular client, I would use the fields PERNR and MANDT as my lock parameters.

    During formulation of these conditions, an AND condition is implied. For instance, you might want to lock employee 2900 in client 300. Then, the condition would be interpreted as "Lock the table entry where PERNR is equal to 2900 AND MANDT is 300."

    Lock modes

    SAP enables you to specify a lock mode that best suits your business requirement. This gives an idea of the intention of the application that employs a particular lock in its code. Let's consider the standard payroll program that locks all the personnel numbers whose payroll results are computed. During execution of this program, no other application is allowed to set a lock for changing the respective employees' data.

    There are three modes of SAP locks:

    Shared. The shared lock is requested by an application that wants to read a particular set of data. If it succeeds, any other application requesting shared locks (on the same data) is allowed. However, any such write lock requests are denied.

    Exclusive and cumulative. This mode is also known as a write lock. It's requested by transactions that update the contents of a particular table. The same transaction may request additional write locks. A cumulative counter, initialized to 0, is provided for this purpose. Each time a particular data is locked via a cumulative lock, the counter is incremented by 1. Any external read locks are denied.

    Exclusive and not cumulative. This mode behaves in a similar fashion to the cumulative lock. The only difference is that cumulative facility is not permissible; a transaction cannot set additional lock entries on data that it has already locked.

    Where do we go from here?

    Two function modules, one for setting locks and the other for releasing them, are automatically generated upon successful activation of the lock object in the ABAP Dictionary. They are of the form ENQUEUE_* and DEQUEUE_*. If we created the lock object E_MYLOCKOBJ, the corresponding locking and unlocking function modules generated would be ENQUEUE_ E_MYLOCKOBJ and DEQUEUE_E_MYLOCKOBJ, respectively.

    Any SAP transaction that wants to employ the SAP locking facility must call these function modules with appropriate parameters. A pseudocode format of all application programs that employ the SAP locking facility appears below:

    CALL relevant ENQUEUE function

    MAKE update

    CALL relevant DEQUEUE function

    A program that sets a lock can only reverse or unlock it. At the end of all transactions, all locks are automatically released.

    The identical interfaces of the ENQUEUE and DEQUEUE modules are of primary importance. These include the lock parameters (previously defined in the ABAP Dictionary) that specify the table entry or entries that are to be locked. It is not necessary to specify lock parameters in full at runtime. If we supply only partial parameters, the generic lock is implied.

    For example, while calling the DEQUEUE function in our PERNR example, we could pass "300" in place of parameter MANDT and leave the parameter PERNR blank. In this case, all employee entries in client 300 would be locked regardless of their personnel numbers.

    When the ENQUEUE function is successful, the value of the return code SY-SUBRC is set to 0. Failure in locking the given entry raises the exception FOREIGN_LOCK. This exception implies that the table entries corresponding to the given parameters have already been locked by another application.

    Lock table

    A lock table is a centralized table in the main memory of the ENQUEUE server that acts as a directory of all locked objects. You can view the contents of this table by using the standard SAP transaction SM12.

    Whenever a new ENQUEUE function is called by an application, an entry is made in this table. Conversely, a DEQUEUE function clears the corresponding entry. When a different program attempts to lock the same object, SAP refers to this table to find out if it is already in a locked state. If not, it is allowed to proceed.

    Included fields are:

    Lock arguments. This is made from the key data of the lock parameter.

    Cumulative counter. In the case of the cumulative lock, this shows the number of times locks have been applied.

    User name. This is the name of the user who has run the application that has applied the lock.

    You can use this table to view the type and arguments of the lock. All lock entries set by a particular transaction are automatically deleted from the table upon the transaction's termination. In case of abrupt termination by the ENQUEUE transaction, you may also manually delete lock entries from this table.

    Conclusion

    Knowledge of the SAP locking mechanism is essential to write even the simplest database update programs. Always follow the golden rule: Try to express your problem in terms of the data fields that are to be locked to formulate the lock condition.

    Please reward points if useful.

    Regards,

    Adarsh Srivastava.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 31, 2008 at 06:44 AM

    Hi

    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

    If it helpful rewards points.

    Regards

    Pratap.M

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.