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

Lock Object Creation

Former Member
0 Likes
2,142

Hi,

Is it possible to create lock objects at runtime? if not, how do I lock tables at runtime when the table name is specified in the selection screen by the user?

Thanks.

Tyken

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,581

You can use FMs ENQUEUE_E_TABLE and DEQUEUE_E_TABLE. Pass table name which you need to lock.

I hope it helps.

Best Regards,

Vibha

Please mark all the helpful answers

7 REPLIES 7
Read only

Former Member
0 Likes
1,582

You can use FMs ENQUEUE_E_TABLE and DEQUEUE_E_TABLE. Pass table name which you need to lock.

I hope it helps.

Best Regards,

Vibha

Please mark all the helpful answers

Read only

0 Likes
1,581

But you can only use these FM's if youve already created a lock object for a specific table in se11.

what if the user inputs, say ZZZTABLE1 in the selection screen, how do I lock this table if there is no lock object defined for it?

Thanks

Read only

Former Member
0 Likes
1,581

create a lock object for that table via SE11->Lock object ... and call function module ENQUEUE_EZ_<TABLE> for locking and DEQUEUE_EZ_<TABLE> for unlocking the table ...

Regards,

Santosh

Read only

Former Member
0 Likes
1,581

Hi tyken,

Try this.

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.

Steps to create lock objects :

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

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

Regards,

Chitra

Read only

anversha_s
Active Contributor
0 Likes
1,581

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 is also sent to the update program.

The lock must be removed in both the dialog program and by the update program.

This is the standard setting for the ENQUEUE function module.

Regards,

Anversha

Read only

Former Member
0 Likes
1,581

My main question is, how do I define a lock object dynamically inside my program? Because I only get the table name from the user, and I dont want to maintain lock objects for all customized tables in the data dictionary.

Thanks.

Tyken

Read only

0 Likes
1,581

Hi Tyken,

You can try the following:

To lock the table

CALL FUNCTION 'ENQUEUE_E_TABLE'

EXPORTING

tabname = table_name

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

Do the required task

To Unlock the Table

CALL FUNCTION 'DEQUEUE_E_TABLE'

EXPORTING

tabname = table_name

Here in the table name you can pass the table name that you are getting in the selection screen. This is a dynamic lock.

Regards,

Chitra