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

Implementing lock object

I've a TCode to modify a report. That TCode picks a doc no. from a table & opens up an editable ALV based on that doc. no .That doc. no. is the only primary key.

I want that if someone is already opened that report, & if someoen else is trying to open that report, it shouldn't open & should show that -"its locked by User XXX". I've made a lock object for that table. Please advise what to do next. How to populate the User name who has locked the report.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Posted on Nov 26, 2007 at 03:31 AM

    Try to use the ENQUEUE function module just before selecting the data from the table. If the table is locked by somebody else the ENQUEUE FM will return SY-SUBRC <> 0.

    Regards,

    Naimesh Patel

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 26, 2007 at 03:38 AM

    used ENQUEUE function and DEQUEUE function

    Function Modules for Lock Requests

    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:

    &#65399; _SCOPE = 1: Locks or lock releases are not passed to the update program. The lock is removed when the transaction is ended.

    &#65399; _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.

    &#65399; _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. The values allowed for this parameter are S (read lock), E (write lock), X (extended write lock), and O (optimistic lock).

    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:

    &#65399; Initial Value: The lock request or lock release is sent directly to the lock server.

    &#65399; 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:

    &#65399; Initial Value: If a lock attempt fails because there is a competing lock, the exception FOREIGN_LOCK is triggered.

    &#65399; 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

    &#65399; 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.

    &#65399; 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

    See also:

    Example for Lock Objects

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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 26, 2007 at 04:36 AM

    Hi

    Before displaying the report in change mode use the function module 'ENQUE_READ' to check if there are any lock entries created already. If there are, show the report in display mode. Otherwise, lock using FM 'ENQUEUE_' and show the report in change mode. Don't forget to remove the lock entry using FM 'DQUEUE_' when the user exits the report.

    Once the lock objects are created you need to apply them in the code using ENQUEUE and DEQUEUE function modules generated for them

    Click GOTO => Function modules.

    It will display 2 FM's. with ENQUEUE_ & DEQUEUE_ as starting

    In your program, to lock use

    ENQUEUE_ ***** FM

    Pass the table level field value details to this FM

    To unlock use

    DEQUEUE_***** FM

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

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

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

    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.