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

Former Member
0 Likes
989

hi to all experts,

how can we used the 'Lock Object' concept

in my coding.please give me a sample code .

thanks in advance and reward also if it useful.

Regards :

Deepsama

11 REPLIES 11
Read only

Former Member
Read only

Former Member
0 Likes
945

Hi,

A lock object is a virtual link of several SAP tables which is used to synchronize simultaneous access by two users to the same set of data ( SAP lock concept).

Locks are requested and released in the programming of online transactions by calling certain function modules which are automatically generated from the definition of the lock objects. These lock objects must be explicitly created in the ABAP Dictionary.

To set locks, you must perform the following steps:

1. You must define a lock object in the ABAP Dictionary. The name of the lock object should begin with E.

2. The function modules for requesting and releasing locks which are created automatically when the lock object is activated must be linked to the programming of the relevant online transactions.

Read only

Former Member
0 Likes
945
Read only

Former Member
Read only

Former Member
0 Likes
945

Hi,

Lock object can be created from SE11 transaction.

The name of the object will start from E and not Z.

Once you create the lock object SAP will create two FMs, one to lock ( Enqueue ) the table and other to unlock ( Dequeue ) the table.

For more details about this concept check the below link :

/community [original link is broken]

Hope this helps!!

Regards,

Lalit

Read only

Former Member
0 Likes
945

Hi,

Example for Lock Objects

When booking flights (see Flight Model) it is important to prevent flights from being overbooked. For this reason, you have to lock the particular flight as well as all the bookings existing for this flight during processing. You can do this with lock object E_BOOKING.

The flights are recorded in table SFLIGHT and the bookings for the flights in table SBOOK. The two tables are linked with a foreign key. Lock object E_BOOKING must therefore contain table SFLIGHT as primary table and table SBOOK as further table

The lock argument of table SFLIGHT thus contains the fields MANDT, CARRID, CONNID, and FLDATE. The lock argument of table SBOOK thus contains the fields MANDT, CARRID, CONNID, FLDATE, BOOKID and CUSTOMID.

Select exclusive lock mode, that is the locked data can only be displayed and edited by one user.

When the lock object is activated, the following function modules are generated from its definition:

ENQUEUE_ E_BOOKING (set locks)

ENQUEUE_ E_BOOKING (release locks)

These function modules can now be linked to ABAP programs.

The following example shows how function module ENQUEUE_ E_BOOKING is called.

CALL FUNCTION 'ENQUEUE_E_BOOKING'

exporting

mode_sflight = ' E '

mode_sbook = ' E '

mandt = sy-mandt

carrid = ' LH '

connid = 400

fldate = ' 19981129 '

With this call, flight LH 400 on Nov. 29,1998 is exclusively (lock mode E) locked in table SFLIGHT together with all the bookings entered in table SBOOK for this flight (since the initial value 0 is transferred for BOOKID and CUSTOMID). The lock is sent to the update program (_SCOPE = u20182u2019). If there is a lock conflict, another attempt is made to set the lock after a certain time (_WAIT = u2018Xu2019).

The set locks can be removed by calling the function module DEQUEUE_E_BOOKING as follows:

CALL FUNCTION 'DEQUEUE_E_BOOKING'

exporting

mode_sflight = ' E '

mode_sbook = ' E '

mandt = sy-mandt

carrid = ' LH '

connid = 400

fldate = ' 19981129 '

The existing exclusive lock entries for flight LH 400 are deleted in table SFLIGHT and the bookings for this flight are deleted in table SBOOK. The request to delete the lock entries is passed on to the update program (_SCOPE = u20183u2019).

Thanks,

Das.............

Read only

Former Member
0 Likes
945

Hi Sapna.

I would suggest you to refer to these references:

[SAP HELP - Examples on Lock Objects|http://help.sap.com/saphelp_nw04/helpdata/en/af/22ab01dd0b11d1952000a0c929b3c3/frameset.htm]

[SDN - Reference for sample code/examples on Lock Objects|;

[SDN - Reference for Lock Objects|;

[SDN - Reference for Lock Objects related examples|;

Hope that's usefull.

Good Luck & Regards

Harsh Dave

Edited by: Harsh Dave on Jul 14, 2008 11:59 AM

Edited by: Harsh Dave on Jul 14, 2008 12:00 PM

Edited by: Harsh Dave on Jul 14, 2008 12:00 PM

Read only

Former Member
0 Likes
945

Hi Deep,

Check the following links.

Basic concept:

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

Types and use:

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

Regards,

Anirban Bhattacharjee

Read only

Former Member
0 Likes
945

Hi!

Check out this link

http://www.erpgenie.com/abaptips/content/view/376/62/

Regards

Abhijeet

Read only

Former Member
0 Likes
945

Hi,

hope this example helps u,

&----


*& Report ZLOCKING *

*& *

&----


*& *

*& *

&----


REPORT zlocking .

DATA : tab_emp TYPE TABLE OF zemp_51772,

wa_emp TYPE zemp_51772.

wa_emp-emp_no = '102'.

wa_emp-emp_id = '157'.

wa_emp-emp_name = 'SIVA'.

wa_emp-emp_dept = 'SAP'.

APPEND wa_emp TO tab_emp.

CLEAR wa_emp.

wa_emp-emp_no = '128'.

wa_emp-emp_id = '138'.

wa_emp-emp_name = 'RAMA'.

wa_emp-emp_dept = 'SAP'.

APPEND wa_emp TO tab_emp.

CLEAR wa_emp.

wa_emp-emp_no = '133'.

wa_emp-emp_id = '121'.

wa_emp-emp_name = 'KRISHNA'.

wa_emp-emp_dept = 'SAP'.

APPEND wa_emp TO tab_emp.

CLEAR wa_emp.

CALL FUNCTION 'ENQUEUE_E_TABLEE'

EXPORTING

mode_rstable = 'X'

tabname = 'ZEMP_51772'

  • varkey =

  • X_TABNAME = ' '

  • X_VARKEY = ' '

  • _SCOPE = '2'

  • _WAIT = ' '

  • _COLLECT = ' '

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3

.

IF sy-subrc EQ 0.

INSERT zemp_51772 FROM TABLE tab_emp.

ENDIF.

CALL FUNCTION 'DEQUEUE_E_TABLEE'

EXPORTING

mode_rstable = 'X'

tabname = 'ZEMP_51772'

  • VARKEY =

  • X_TABNAME = ' '

  • X_VARKEY = ' '

  • _SCOPE = '3'

  • _SYNCHRON = ' '

  • _COLLECT = ' '

.

IF sy-subrc EQ 0.

WRITE:/ 'Unlocked the Table'.

ENDIF.

please refer to the links below

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

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

With thanks & regards,

Sravani yendru

Read only

Former Member
0 Likes
945

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_. to insert the object in a queue.

2. DEQUEUE_. To remove the object is being queued through above FM.

You have to use these function module in your program.

For sample program check in transaction /ABAPDOCU.

Regards,

Sachin