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 objects

Former Member
0 Likes
2,521

HI,

I was inserting in five tables simaltenously..If 10 members at the same time when they click the button means its throwing error..

So i need to use lock objects..If one enters tht loop of inserting to tables,it must want to not to allow others inside tht..

Can any one help how to use this and implement in the program

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,264

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.

check this link for example.

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

tables:vbak.

call function 'ENQUEUE_EZLOCK3'

exporting

mode_vbak = 'E'

mandt = sy-mandt

vbeln = vbak-vbeln

  • X_VBELN = ' '

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

Normally ABAPers will create the Lock objects, because we know when to lock and how to lock and where to lock the Object then after completing our updations we unlock the Objects in the Tables

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

purpose: If multiple user try to access a database object, inconsistency may occer. To avoid that inconsistency and to let multiple user give the accessibility of the database objects the locking mechanism is used.

Steps: first we create a loc object in se11 . Suppose for a table mara. It will create two functional module.:

1. enque_lockobject

1. deque_lockobject

before updating any table first we lock the table by calling enque_lockobject fm and then after updating we release the lock by deque_lockobject.

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

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

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

Match Code Objects:

http://help.sap.com/saphelp_nw2004s/helpdata/en/41/f6b237fec48c67e10000009b38f8cf/content.htm

http://searchsap.techtarget.com/tip/0,289483,sid21_gci553386,00.html

See this link:

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

Check these links -

Cheers,

vasavi.v

6 REPLIES 6
Read only

Former Member
0 Likes
2,264

hi,

Create a lock object via SE11->Lock object and call the ENQUEUE_EZ_<TABLE> before updating the table and DEQUEUE_EZ_<TABLE> to unlock after updating the table ...

Regards,

Santosh

Read only

0 Likes
2,264

can u give the function module sample how to use tht

Read only

0 Likes
2,264

LOOP AT i_zrem_alloc_updat_x.

CLEAR i_zrem_alloc_updat_x-lock_message.

CALL FUNCTION 'ENQUEUE_EZREMALLOCUPDAT'

EXPORTING

mode_zrem_alloc_updat = 'E'

mandt = sy-mandt

ext_ref_no = i_zrem_alloc_updat_x-ext_ref_no

  • X_EXT_REF_NO = ' '

  • _SCOPE = '2'

  • _WAIT = ' '

  • _COLLECT = ' '

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

IF sy-subrc <> 0.

i_zrem_alloc_updat_x-icon_name = 'ICON_LOCKED'.

SELECT SINGLE text FROM t100 INTO i_zrem_alloc_updat_x-lock_message

WHERE sprsl = 'E'

AND arbgb = sy-msgid

AND msgnr = sy-msgno.

Go through the code.

Regards,

Madan.

Read only

Former Member
0 Likes
2,264

Hi,

Create the lock object for your requirement (EZ......)

After activating the lockobject it will generate the two function module like ENQUE_EZ.......

DEQUE_EZ........

Before you want to process the record you just call the first function module and lock the table .... for your entry.

And after processing the same to unlock the table call the second function module.

Regards,

Madan.

Read only

Former Member
0 Likes
2,264

Hi,

you want kep lock on 5tables right.

first select primary table among 5 tables.

First create lock object starting with ez or ey .

go to se11 enter name press create.

there enter primary table and select exclusive not cumulative mode.

press add button enter remaining tables .

after activate that lock object.

It will restrict from other users access.

after we can request lock explicitly in abap program using enqueue_lockobject and dequeue_lockobject.

but we can request lock on single table link has to create in se11 using lock object for other tables.

Requesting an SAP lock

When a lock object obj is activated, two function modules (see CALL

FUNCTION) with the names ENQUEUE_obj and DEQUEUE_obj are generated.

These lock modules are used to explicitly request or release SAP locks

in an ABAP program. The SAP lock concept thus assumes a cooperative

behavior by all the programs involved. This means that access from

programs that do not call the specified modules are not protected.

The lock conditions and lock modes for the requested locks are defined

by the IMPORT parameters of the lock modules.

The lock conditions are defined by the lock parameters of the lock

object. If the lock object has only one base table, each primary key

field of the table corresponds to exactly one lock parameter. Apart from

this, a lock parameter corresponds to a group of primary key fields that

are identified by the join conditions. For each lock parameter par, the

lock modules have two IMPORT parameters with the names par and X_par.

The lock condition is defined by these parameters. If a parameter par is

not defined or if it is defined with the initial value, this means that

the corresponding key fields should be locked generically. If you really

want to lock the key field with the initial value, you must also define

the parameter X_par with the value 'X'.

To define the lock modes, the lock modules have an IMPORT parameter

MODE_tab for each base table tab, with which the lock mode for this

table can be defined. A default value must already be set for this

parameter in the definition of the lock object.

this is second procedure.

each explicit locking process assumes that all programs which perform database accesses work together in a cooperative manner. If a program does not behave in this way, i.e. it reads or changes data without locking it beforehand, this may result in a conflict with another program, even this other program has locked data correctly.

The following program fragment presents a solution to this problem:

TABLES: SFLIGHT, SBOOK.

CALL FUNCTION 'ENQUEUE_ESFLIGHT'

EXPORTING MANDT = SY-MANDT

CARRID = 'LH'

CONNID = '0400'

FLDATE = '19960516'

MODE_SFLIGHT = 'E'

EXCEPTIONS FOREIGN_LOCK = 1

OTHERS = 2.

CASE SY-SUBRC.

WHEN 1. ...

WHEN 2. ...

ENDCASE.

SELECT SINGLE * FROM SFLIGHT

WHERE

CARRID = 'LH' AND

CONNID = '0400' AND

FLDATE = '19960516'.

IF SY-SUBRC <> 0.

MESSAGE E...

ENDIF.

IF SFLIGHT-SEATSOCC < SFLIGHT-SEATSMAX.

SBOOK-CARRID = 'LH'.

SBOOK-CONNID = '0400'.

SBOOK-FLDATE = '19960516'.

...

INSERT SBOOK.

IF SY-SUBRC <> 0.

MESSAGE E...

ENDIF.

UPDATE SFLIGHT

SET

SEATSOCC = SEATSOCC + 1

WHERE

CARRID = 'LH ' AND

CONNID = '0400' AND

FLDATE = '19960516'.

ELSE.

MESSAGE E...

ENDIF.

CALL FUNCTION 'DEQUEUE_ESFLIGHT'

EXPORTING MANDT = SY-MANDT

CARRID = 'LH'

CONNID = '0400'

FLDATE = '19960516'

MODE_SFLIGHT = 'E'.

COMMIT WORK.

*Reward points

Edited by: jeevitha on May 7, 2008 10:27 AM

Edited by: jeevitha on May 7, 2008 10:33 AM

Edited by: jeevitha on May 7, 2008 10:39 AM

Read only

Former Member
0 Likes
2,265

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.

check this link for example.

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

tables:vbak.

call function 'ENQUEUE_EZLOCK3'

exporting

mode_vbak = 'E'

mandt = sy-mandt

vbeln = vbak-vbeln

  • X_VBELN = ' '

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

Normally ABAPers will create the Lock objects, because we know when to lock and how to lock and where to lock the Object then after completing our updations we unlock the Objects in the Tables

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

purpose: If multiple user try to access a database object, inconsistency may occer. To avoid that inconsistency and to let multiple user give the accessibility of the database objects the locking mechanism is used.

Steps: first we create a loc object in se11 . Suppose for a table mara. It will create two functional module.:

1. enque_lockobject

1. deque_lockobject

before updating any table first we lock the table by calling enque_lockobject fm and then after updating we release the lock by deque_lockobject.

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

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

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

Match Code Objects:

http://help.sap.com/saphelp_nw2004s/helpdata/en/41/f6b237fec48c67e10000009b38f8cf/content.htm

http://searchsap.techtarget.com/tip/0,289483,sid21_gci553386,00.html

See this link:

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

Check these links -

Cheers,

vasavi.v