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: 

hi lockobj

Former Member
0 Kudos

hi all

how can i lock single record using lock object.

thanx

rocky

1 ACCEPTED SOLUTION

Former Member
0 Kudos

HI

<b><u>Type and Uses of Lock Objects in SAP</u></b>

<b>How many types of lock objects?

How to create Lock objects?

What is the main use of it in real time?</b>

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.

<b>Use:</b> 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.

<b>Example:</b> 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.

<b>Technicaly:</b>

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.

<b>You have to use these function module in your program.</b>

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.

Check these links

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

http://help.sap.com/saphelp_nw2004s/helpdata/en/cf/21ea31446011d189700000e8322d00/frameset.htm

http://help.sap.com/saphelp_nw04/helpdata/en/7b/f9813712f7434be10000009b38f8cf/content.htm

http://dev.mysql.com/doc/maxdb/en/a6/1e3bb904e811d2a96c00a0c9449261/content.htm

http://dev.mysql.com/doc/maxdb/en/c4/812640632cec01e10000000a155106/content.htm

http://sap.ittoolbox.com/groups/technical-functional/sap-dev/lock-objects-170328#

Reward all helpfull answers

Regards

Pavan

5 REPLIES 5

0 Kudos

HI,

You need to call the ENQUEUE_XXXX Function module by passing all the Primary keys of the table, that is all the IMPORT parameters of the Function module.

Alternatively you can use SELECT SINGLE with FOR UPDATE addition to lock the record.

Regards,

Sesh

0 Kudos

for locking the table also u do the same thing then what is the diff here

Former Member
0 Kudos

Hi Rocky,

Refer to this related thread

Former Member
0 Kudos

HI

<b><u>Type and Uses of Lock Objects in SAP</u></b>

<b>How many types of lock objects?

How to create Lock objects?

What is the main use of it in real time?</b>

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.

<b>Use:</b> 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.

<b>Example:</b> 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.

<b>Technicaly:</b>

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.

<b>You have to use these function module in your program.</b>

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.

Check these links

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

http://help.sap.com/saphelp_nw2004s/helpdata/en/cf/21ea31446011d189700000e8322d00/frameset.htm

http://help.sap.com/saphelp_nw04/helpdata/en/7b/f9813712f7434be10000009b38f8cf/content.htm

http://dev.mysql.com/doc/maxdb/en/a6/1e3bb904e811d2a96c00a0c9449261/content.htm

http://dev.mysql.com/doc/maxdb/en/c4/812640632cec01e10000000a155106/content.htm

http://sap.ittoolbox.com/groups/technical-functional/sap-dev/lock-objects-170328#

Reward all helpfull answers

Regards

Pavan

Former Member
0 Kudos

Hi,

look at the below link to create the lock object with a Single record

http://help.sap.com/saphelp_nw04s/helpdata/en/af/22ab01dd0b11d1952000a0c929b3c3/content.htm

Regards

Sudheer