Skip to Content
avatar image
Former Member

lock objects

plz explain abt lock objects, types of lock objects(shared,exclusive,cumulative) and how 2 create lock objects.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

10 Answers

  • avatar image
    Former Member
    Feb 11, 2007 at 05:28 AM

    Hi,

    Lock objects are used to lock the database table while making the modifications on the database table.

    you can create your own lock objects using SE11.

    if you create lock objects on any table system will create two function modules.

    1.ENQUEUE....

    2.DEQUEUE.....

    first one is used to lock the table

    second one used to removing lock on the table.

    *----


    lock Table

    CALL FUNCTION 'ENQUEUE_E_TABLE'

    EXPORTING

    tabname = table_name

    EXCEPTIONS

    foreign_lock = 1

    system_failure = 2

    OTHERS = 3.

    *----


    Unlock Table

    CALL FUNCTION 'DEQUEUE_E_TABLE'

    EXPORTING

    tabname = table_name

    check this link :

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

    _SCOPE = 1: The lock is not sent to the update program. The lock is removed when the transaction is ended.

    _SCOPE = 2: The lock is sent to the update program. The update program is responsible for removing the lock. The dialog program which requested the lock no longer has an influence on the lock behavior. This is the standard setting for the ENQUEUE function module.

    _SCOPE = 3: The lock

    Regards,

    Anver

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 11, 2007 at 07:31 AM

    Hello,

    1)Go to se11 transaction.

    2)Click on lock object radio button and give a lock object name starting with 'E'.For example 'ESAMPLE'.Click CREATE.

    3)In the TABLE tab, you can give the table name for which you require a lock.In the LOCK PARAMETERS tab,you can give the table fields based on which the table should be locked.

    4)Call a function module in your program ENQUEUE_lockobjectname to obtain a lock on the required table.In our example the FM will be ENQUEUE_ESAMPLE.

    5)To release the lock on the table,call the function module DEQUEUE_lockobjectname.In our example the FM will be DEQUEUE_ESAMPLE.

    Lock objects

    lock-objects?

    Regards,

    Beejal

    **Reward if answer helps.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 11, 2007 at 11:00 PM

    Hi

    In SAP lock objects are used to maintain the consistency in the database and applications by giving authorization to update any record to a single user only.

    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.

    Now SAP has come up with another lock mechanism called Optimistic lock. Which initially work like shared(many user can access the object in update mode) but the data will be saved by the user who saves the object first at this point this lock turns into exclusive mode and all the shared lock is released.

    And to create lock objects you use SE11 and enter the lock object name EZ..... thereafter locking of tables depend on your requirement and relationship between the tables.

    For coding and different parameters of ENQEUE and DEQEUE refer to help.sap.com.

    Hope this helps.

    Regards

    Amit

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 12, 2007 at 05:10 AM

    I cudn't resist myself asking this question:

    Suppose I have one program in which I am using a transaction to do some specific work and while this program is running , I don't want anyone to access that transaction. Can i bolck the transaction using lock object?? If yes,then how to do it?? If not then how can i do it?

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 12, 2007 at 05:14 AM

    Hi Neela,

    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.

    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

    Create lock object.

    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

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

    Regards,

    Priyanka.

    null

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 12, 2007 at 08:34 PM

    Hi Neela

    Go through the following Document & sample Code for Lock Objects

    Lock entries

    Use transaction SM12 Lock entries to see lock entries

    Naming: The lock object name must start with EZ

    Create the lock object for the required table using SE11. When you create the locl object, two function

    modules will be created automatically. These two function modules named

    ENQUEUE_<lock object name> and DEQUEUE_<lock object name> can be called to lock or dislock

    the table.

    Example:

    Create a lock object for table MSEG called EZTESTLOCK.

    When you has created the lock object, the two function modules

    ENQUEUE_EZTESTLOCK

    DEQUEUE_EZTESTLOCK

    Will automatically be created

    REPORT lockentries.

    PARAMETERS:

    p_mbelnr LIKE mseg-mblnr DEFAULT '4900008001',

    p_mjahr LIKE mseg-mjahr DEFAULT '2001',

    p_zeile LIKE mseg-zeile DEFAULT 1,

    p_lock RADIOBUTTON GROUP lock,

    p_unlock RADIOBUTTON GROUP lock.

    START-OF-SELECTION.

    IF p_lock = 'X'.

    • Lock item

    CALL FUNCTION 'ENQUEUE_EZTESTLOCK'

    EXPORTING

    • MODE_MSEG = 'E'

    • MANDT = SY-MANDT

    mblnr = p_mbelnr

    mjahr = p_mjahr

    zeile = p_zeile

    • X_MBLNR = ' '

    • X_MJAHR = ' '

    • X_ZEILE = ' '

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

    ELSEIF p_unlock = 'X'.

    • Unlock item

    CALL FUNCTION 'DEQUEUE_EZTESTLOCK'

    EXPORTING

    • MODE_MSEG = 'E'

    • MANDT = SY-MANDT

    mblnr = p_mbelnr

    mjahr = p_mjahr

    zeile = p_zeile

    • X_MBLNR = ' '

    • X_MJAHR = ' '

    • X_ZEILE = ' '

    • _SCOPE = '3'

    • _SYNCHRON = ' '

    • _COLLECT = ' '

    .

    ENDIF.

    Regards

    Sreeni

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 13, 2007 at 06:45 AM
    Add comment
    10|10000 characters needed characters exceeded

  • Feb 16, 2007 at 03:58 AM

    Neela,

    I had gone through your question and also the replies for the same.One more point I would like to add "what happens when a lock object is created?"

    when we create a lock object,basically it locks the Primary Key of that particular table thus preventing other users from accessing the same table for any manipulations.

    K.Kiran..

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 16, 2007 at 01:10 PM

    Hi Neela,

    LOCK OBJECTS

    1)Go to se11 transaction.

    2)Click on lock object radio button and give a lock object name starting with 'E'.For example 'ESAMPLE'.Click CREATE.

    3)In the TABLE tab, you can give the table name for which you require a lock.In the LOCK PARAMETERS tab,you can give the table fields based on which the table should be locked.

    4)Call a function module in your program ENQUEUE_lockobjectname to obtain a lock on the required table.In our example the FM will be ENQUEUE_ESAMPLE.

    5)To release the lock on the table,call the function module DEQUEUE_lockobjectname.In our example the FM will be DEQUEUE_ESAMPLE.

    Go through the following Sample Example for Creating a Lock Object

    Use transaction SM12 Lock entries to see lock entries

    Naming: The lock object name must start with EZ

    Create the lock object for the required table using SE11. When you create the locl object, two function

    modules will be created automatically. These two function modules named

    ENQUEUE_<lock object name> and DEQUEUE_<lock object name> can be called to lock or dislock

    the table.

    Example:

    Create a lock object for table MSEG called EZTESTLOCK.

    When you has created the lock object, the two function modules

    ENQUEUE_EZTESTLOCK

    DEQUEUE_EZTESTLOCK

    Will automatically be created

    REPORT lockentries.

    PARAMETERS:

    p_mbelnr LIKE mseg-mblnr DEFAULT '4900008001',

    p_mjahr LIKE mseg-mjahr DEFAULT '2001',

    p_zeile LIKE mseg-zeile DEFAULT 1,

    p_lock RADIOBUTTON GROUP lock,

    p_unlock RADIOBUTTON GROUP lock.

    START-OF-SELECTION.

    IF p_lock = 'X'.

    • Lock item

    CALL FUNCTION 'ENQUEUE_EZTESTLOCK'

    EXPORTING

    • MODE_MSEG = 'E'

    • MANDT = SY-MANDT

    mblnr = p_mbelnr

    mjahr = p_mjahr

    zeile = p_zeile

    • X_MBLNR = ' '

    • X_MJAHR = ' '

    • X_ZEILE = ' '

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

    ELSEIF p_unlock = 'X'.

    • Unlock item

    CALL FUNCTION 'DEQUEUE_EZTESTLOCK'

    EXPORTING

    • MODE_MSEG = 'E'

    • MANDT = SY-MANDT

    mblnr = p_mbelnr

    mjahr = p_mjahr

    zeile = p_zeile

    • X_MBLNR = ' '

    • X_MJAHR = ' '

    • X_ZEILE = ' '

    • _SCOPE = '3'

    • _SYNCHRON = ' '

    • _COLLECT = ' '

    .

    ENDIF.

    Regards

    Sreeni

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 21, 2007 at 07:03 PM

    Hi neela renganathan

    Lock Objects

    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.

    Example for Lock Objects

    When booking flights (see Flight Model) it is important to prevent flights from being overbooked. For this reason, you have to lock the

    particular flight as well as all the bookings existing for this flight during processing. You can do this with lock object E_BOOKING.

    The flights are recorded in table SFLIGHT and the bookings for the flights in table SBOOK. The two tables are linked with a foreign key. Lock

    object E_BOOKING must therefore contain table SFLIGHT as primary table and table SBOOK as further table.

    The lock argument of table SFLIGHT thus contains the fields MANDT, CARRID, CONNID, and FLDATE. The lock argument of table SBOOK thus

    contains the fields MANDT, CARRID, CONNID, FLDATE, BOOKID and CUSTOMID.

    Select exclusive lock mode, that is the locked data can only be displayed and edited by one user.

    When the lock object is activated, the following function modules are generated from its definition:

    ENQUEUE_ E_BOOKING (set locks)

    ENQUEUE_ E_BOOKING (release locks)

    These function modules can now be linked to ABAP programs.

    The following example shows how function module ENQUEUE_ E_BOOKING is called.

    With this call, flight LH 400 on Nov. 29,1998 is exclusively (lock mode E) locked in table SFLIGHT together with all

    the bookings entered in table SBOOK for this flight (since the initial value 0 is transferred for BOOKID and

    CUSTOMID). The lock is sent to the update program (_SCOPE = ‘2’). If there is a lock conflict, another attempt is

    made to set the lock after a certain time (_WAIT = ‘X’).

    The set locks can be removed by calling the function module DEQUEUE_E_BOOKING as follows:

    The existing exclusive lock entries for flight LH 400 are deleted in table SFLIGHT and the

    bookings for this flight are deleted in table SBOOK. The request to delete the lock entries is

    passed on to the update program (_SCOPE = ‘3’).

    Function Modules for Lock Requests

    Activating a lock object in the ABAP Dictionary automatically creates function modules for setting (ENQUEUE_.

    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.

    Whenever you have lock mode X (extended write lock), locks should not be written to the local lock container if very many locks refer to the

    same lock table. In this case, there will be a considerable loss in performance in comparison with direct transmission of locks.

    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.

    or

    refer the following link

    http://allsaplinks.com/lock_objects.html

    Add comment
    10|10000 characters needed characters exceeded