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

how to create a lock object in se11

Former Member
0 Likes
4,164

hi all,

Can anyone tell me the step by step procedure to lock as well as unlock a particular object in se11 trns code. with an real time example.

thanxs in advance

hari

hi all,

Can anyone tell me the step by step procedure to lock as well as unlock a particular object in se11 trns code. with an real time example.

thanxs in advance

hari

4 REPLIES 4
Read only

Former Member
0 Likes
2,512

Hi,

folow these steps.

1) Select object type Lock object in the initial screen of the ABAP Dictionary, enter an object name and choose Create. The name of a lock object should begin with an E (Enqueue).

The maintenance screen for lock objects is displayed.

2) Enter an explanatory short text in the field Short text.

You can then use the short text to find the lock object at a later time, for example with the R/3 Repository Information System.

3) Enter the name of the primary table of the lock object.

All other tables in the lock object must be linked with the primary table using foreign keys. There are also some restrictions on the valid foreign key relationships.

4) Select the lock mode of the primary table in the field below it.

The lock mode is used as the default value for the corresponding parameters of the function modules generated from the lock object.

5) Choose Add if you want to lock records in more than one table with the lock object.

A list of all the tables linked with the primary table using valid foreign keys is displayed. Select the appropriate table. The lock mode of the primary table is copied as lock mode. You can change this setting as required, for example you can assign the lock mode separately for each table.

Similarly, you can add a table linked with the secondary table just added with foreign keys. To do this, place the cursor on the name of the secondary table and choose Add.

If no lock mode is assigned to a table, no lock is set for the entries in this table when the generated function modules are called. You should not assign a lock mode if a secondary table was only used to define a path between the primary table and another secondary table with foreign keys.

6) Save your entries.

A dialog box appears in which you have to assign the lock object a development class.

7) You can (optionally) exclude lock parameters (see lock objects) from the function module generation on the Lock parameter tab page. This makes sense for example if you always want to lock a parameter generically.

To do this, simply deselect the Weight flag for the parameter. The parameter is not taken into consideration in the generated function modules. This parameter is then always locked generically.

The name of a lock parameter is usually the name of the corresponding table field. If two fields with the same name are used as lock parameters in the lock object from different tables, you must choose a new name for one of the fields in field Lock parameter.

You can define whether the function modules generated from the lock object should be RFC-enabled on the Attributes tab page.

If you set the Allow RFC flag, the generated function modules can be called from within another system with Remote Function Call.

😎 If you permit Remote Function Calls for an existing lock object, you must ensure that the generated function modules are called from within an ABAP program with parameters appropriate for the type. You should therefore check all programs that use the associated function modules before activating the lock object with the new option.

9) Choose EXECUTE.

Result

When you activate the lock object, the two function modules ENQUEUE_<lockobjectname> and DEQUEUE_<lockobjectname> are generated from its definition to set and release locks.

You can find information about the activation flow in the activation log, which you can display with Utilities--->Activation log. If errors occurred during activation, the activation log is displayed immediately.

Regards,

Priyanka.

Read only

Former Member
0 Likes
2,512

Hi,

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.

Creating Lock Objects

Procedure

1.Select object type Lock object in the initial screen of the ABAP Dictionary, enter an object name and choose Create. The name of a lock object should begin with an E (Enqueue).

The maintenance screen for lock objects is displayed.

2.Enter an explanatory short text in the field Short text.

You can then use the short text to find the lock object at a later time, for example with the R/3 Repository Information System.

3.Enter the name of the primary table of the lock object.

All other tables in the lock object must be linked with the primary table using foreign keys. There are also some restrictions on the valid foreign key relationships.

4.Select the lock mode of the primary table in the field below it.

The lock mode is used as the default value for the corresponding parameters of the function modules generated from the lock object.

5.Choose Add if you want to lock records in more than one table with the lock object.

A list of all the tables linked with the primary table using valid foreign keys is displayed. Select the appropriate table. The lock mode of the primary table is copied as lock mode. You can change this setting as required, for example you can assign the lock mode separately for each table.

6.Similarly, you can add a table linked with the secondary table just added with foreign keys. To do this, place the cursor on the name of the secondary table and choose Add.

7.If no lock mode is assigned to a table, no lock is set for the entries in this table when the generated function modules are called. You should not assign a lock mode if a secondary table was only used to define a path between the primary table and another secondary table with foreign keys.

8.Save your entries.

A dialog box appears in which you have to assign the lock object a development class.

9.You can (optionally) exclude lock parameters (see lock objects) from the function module generation on the Lock parameter tab page. This makes sense for example if you always want to lock a parameter generically.

To do this, simply deselect the Weight flag for the parameter. The parameter is not taken into consideration in the generated function modules. This parameter is then always locked generically.

9.The name of a lock parameter is usually the name of the corresponding table field. If two fields with the same name are used as lock parameters in the lock object from different tables, you must choose a new name for one of the fields in field Lock parameter.

10.You can define whether the function modules generated from the lock object should be RFC-enabled on the Attributes tab page.

If you set the Allow RFC flag, the generated function modules can be called from within another system with Remote Function Call.

11.If you permit Remote Function Calls for an existing lock object, you must ensure that the generated function modules are called from within an ABAP program with parameters appropriate for the type. You should therefore check all programs that use the associated function modules before activating the lock object with the new option.

12 .Choose Activate .

Result

When you activate the lock object, the two function modules ENQUEUE_<lockobjectname> and DEQUEUE_<lockobjectname> are generated from its definition to set and release locks.

You can find information about the activation flow in the activation log, which you can display with Utilities Activation log. If errors occurred during activation, the activation log is displayed immediately.

Pls reward points.

Regards,

Ameet

Message was edited by:

Ameet Jassani

Read only

Former Member
0 Likes
2,512

Hi Hari,

Type and Uses of Lock Objects in SAP

How many types of lock objects?

How to create Lock objects?

What is the main use of it in real time?

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.

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.

<b>say thanks by rewarding pts in SDN</b>

Regards

Sathish:)

Read only

Former Member
0 Likes
2,512

Hi all,

Thanxs a lot for the quick response. I have assigned points for everyone.

regds

hari