Application Development 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: 

Enqueue and Dequeue consept----Please explain urgent

Former Member
0 Kudos

hi all,

i want to use sap locking mechanisn (Enqueue and dequeue consept) while updating database table....please explain how to use this while updating a database table.

Thanks in advance

Nandha kumar

8 REPLIES 8

Former Member
0 Kudos

Enqueue and Dequeue are based on t he Lock objects created via SE11. When a lock object is created for a DB table, 2 Function Modules are created:

1. ENQUEUE_<lock object>

2. DEQUEUE_<lock object>

Before every update of the DB use the ENQUEUE FM and after COMMIT WORK use the DEQUEUE fm.

Former Member
0 Kudos

The enqueue concept is used to prevent two or more processes attempting to update a database record at the same time.

For example, to lock or unlock PERNR use FMs,

CALL FUNCTION 'BAPI_EMPLOYEE_ENQUEUE'

EXPORTING

NUMBER = number .

  • IMPORTING

  • RETURN = .

CALL FUNCTION 'BAPI_EMPLOYEE_DEQUEUE'

EXPORTING

NUMBER = number.

  • IMPORTING

  • RETURN = .

reward if uesful.

Former Member
0 Kudos

go thorugh it

<a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm">http://help.sap.com/saphelp_nw2004s/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm</a>

regards

shiba dutta

Former Member
0 Kudos

Hi

Search for standard FM's like ENQUEUE_* and DEQUEUE_* in SE37.

Most of the standard tables will have this. Use them to lock and unlock the tables.

Regards

Subramanian

Former Member
0 Kudos

Nanda,

simultanious accessing of same record by two different parties can be prevented using locking mechanism.

b4 modifying a record, user locks, so that no other person can be accessed it at taht time. then modifies the data, then again he releases the lock.

if the same record is accessed by more than one party and modifyied, and then stored means,<b> correctness of that record wil be lost.</b>

to achive this concept in SAP, first youn eed to create a lock object,

in se11, select Lock Object, and the naming convention for this is , it should start with EZ or EY .

whenever u create a lock object, then automatically two FMs can be create, one is ENQUEUE and other is DEQUEUE.

use ENQUEUE for locking, and DEQUEUE for unlocking.

Hope this info may help u out.

regards,

Sujatha.

Message was edited by:

Sujatha Reddy

Former Member
0 Kudos

Nandha,

Good document on this concept..

*******************************************

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

Pls. reward if useful

Former Member
0 Kudos

hi

lock object is created in se11.the name should start with EZ.Then we can lock any db table.that can be specified in lock object.

Once lock object is created 2 function module gets created.

ENQUEUE

DEQUEUE.

After updating u can lock using enqueue for a particular field using

FIELD <fieldname> MODULE <modulename> ON REQUEST

or lock the whole table .this is done in PAI.

U can unlock using DEQUEUE ALL function module also.

when u 'SAVE'.or come out of screen.

Hope this is useful

Regards

shinu

Former Member
0 Kudos

hi,

enqueue,dequeue are two function modules which are used

for crating the lock for the data base and remove the lock from the data

base table.