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: 

lock objects

Former Member
0 Kudos

Gurus,

I have created Ztable, for this how to lock the table and how to lock a record?

could any one explain the process of creating a lock object, how to unclock the table or record?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

regards

Giridhar

21 REPLIES 21

Former Member
0 Kudos

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.

regards

Giridhar

0 Kudos

i hv created a zemp1 table and maintaining 3 fields, empno(primary key), ename, dno.

i hv created a lock object..

but it is going to DUMP.

Tables : Zemp1.

CALL FUNCTION 'ENQUEUE_EZEMP1'

EXPORTING

MODE_ZEMP1 = 'E'

EMPNO = 102.

  • X_EMPNO = ' '

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

messier31
Active Contributor
0 Kudos

Hi,

1. <b><a href="http://help.sap.com/saphelp_nw04/helpdata/en/cf/21eef3446011d189700000e8322d00/frameset.htm">Create lock objects</a></b>

2. <b><a href="http://help.sap.com/saphelp_nw04/helpdata/en/af/22ab01dd0b11d1952000a0c929b3c3/frameset.htm">Example for lock object</a></b>

Misc : <b><a href="http://help.sap.com/saphelp_nw04/helpdata/en/af/22ab01dd0b11d1952000a0c929b3c3/frameset.htm">Lock Mechanism</a></b>

Enjoy SAP.

Pankaj Singh.

Former Member
0 Kudos

Hi

Lock object concept

Lock modes

Creating a lock object (example)

Lock object sample code

<b>Lock Objects</b> SAP data dictionary provides you with a locking mechanism to synchronize simultaneous data access by different users.

Lock objects are created in SE11.

Customer lock objects must begin with EY or EZ .

Three possible lock modes exist for lock objects.

<b>LOCK MODE</b>

Lock mode E: This sets a lock for changing data for single user. This lock can be accumulated.

Lock mode X: This mode is used like mode E for changing data. The only technical difference from mode E is that the respective lock does not allow accumulation.

Lock mode S: This mode ensures that data displayed in your program cannot be changed by other users during the entire display time. Here you do not want to change the data yourself (allows read only access for data).

<b>Creating Lock object</b>

Enter lock object name beginning with EY or EZ

and hit create.

Enter table names containing data records that should be locked and the lock mode.

The primary keys of the specified tables are automatically selected as lock parameters.

To set a lock in the application program

call a function module ENQUEUE_<LOCK_OBJECT>.

For our example, it would be ENQUEUE_EZMARA.

To release the lock in the application program

call a function module DEQUEUE_<LOCK_OBJECT>.

For our example, it would be DEQUEUE_EZMARA.

Refer the code executed by user (say abap1) for

matnr = ’000000000000000012’.

REWARD IF USEFULL

Former Member
0 Kudos

Hi,

you see the following steps to create and use the lock objects.

suppose you created one z table called '<b>ZVIJ</b>' for that you need to create lock objects.

Creating Lock object

Enter lock object name beginning with <b>EY or EZ</b> example <b>EZVIJ</b>

and hit create.

Enter table names is <b>ZVIJ</b> containing data records that should be locked and the lock mode.The primary keys of the specified tables are automatically selected as lock parameters.And press the 'activate' button, then lock objects creates by default two Funtion modules are

1) ENQUEUE_EZVIJ (for Lock create)

2) DEQUEUE_EZVIJ (Relase lock)

<b>NOTE: dont forget to active the lock objects until unless activate sys doesnot create the F.Ms</b>

To set a lock in the programs

call a function module ENQUEUE_EZVIJ

To release the lock in the application program

call a function module DEQUEUE_EZVIJ

<b>Reward with points if helpful.</b>

Regards,

Vijay

Former Member
0 Kudos

Hi,

Goto tcode SE11

choose "lock object" (the last option)

Give a name starts with 'E' follwed by ur table name.For Ex: EZTESTTAB.And

click on create.

give description .

click on Tables tab.

jus give name of the table on which u want to create the lock ...and lock mode.

There r differrent kind of locks:

Lock mode E: This sets a lock for changing data for single user. This lock can be accumulated.

Lock mode X: This mode is used like mode E for changing data. The only technical difference from mode E is that the respective lock does not allow accumulation.

Lock mode S: This mode ensures that data displayed in your program cannot be changed by other users during the entire display time. Here you do not want to change the data yourself (allows read only access for data).

then add or remove secondary tables if u r table have any ..

jus save and active.

after this the system will automaticall create two functiona modules named

ENQUEUE_<UR lockname> -for locking a table

DEQUEUE_<UR lockname> -for unlocking a table.

u can call these function modules directly in ur report to lock and unlock that table.

Reward if useful.

Thanks,

jyothi D

0 Kudos

` hv created a zemp1 table and maintaining 3 fields, empno(primary key), ename, dno.

i hv created a lock object..and i hv called the FM...but it is going to DUMP.

Tables : Zemp1.

CALL FUNCTION 'ENQUEUE_EZEMP1'

EXPORTING

MODE_ZEMP1 = 'E'

EMPNO = 102.

  • X_EMPNO = ' '

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

Former Member
0 Kudos

Jus uncomment the "exceptions" part.....

hope it works....

CALL FUNCTION 'ENQUEUE_EZEMP1'

EXPORTING

MODE_ZEMP1 = 'E'

EMPNO = 102.

  • X_EMPNO = ' '

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

Reward if useful.

Jyothi D

0 Kudos

hi jyothi..

its not wrkng... it is gng to dump

Former Member
0 Kudos

what is a match code ? Lock objects ?

The MATCH CODE is nothing but a DDIC search help. If you want to assign a search help to a PARAMETERS or SELEC-OPTIONS in your report program you can use MATCH CODE followed by name of the DDIC search help. Make sure that the DATA ELEMENTS are matched when you make the assignment.

for more information on search help please referr the following link it help you

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

-


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.

regards,

srinivas

Former Member
0 Kudos

Did u do the same thing like this....

CALL FUNCTION 'ENQUEUE_EZEMP1'

EXPORTING

MODE_ZEMP1 = 'E'

EMPNO = 102.

  • X_EMPNO = ' '

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

Former Member
0 Kudos

Try commenting exporting also!!!!

0 Kudos

if i comment on Exporting , how do u pass the Mode and Empno as parameters.?

Former Member
0 Kudos

And At the end call DEQUEUE_EZTEMP also.....

But dont uncomment anything there.......

Former Member
0 Kudos

First of all why do u want to pass the lock mode as 'e'.

This lock mode u mighjt hav defined while creating the lock object in Data dictionary itself....once if i can see the code.....i can tell i think.........

0 Kudos

thisz the code

wen im created , i hv mention the Lock mode as "Read Lock'" in ECC6.0

Tables : Zemp1.

CALL FUNCTION 'ENQUEUE_EZEMP1'

EXPORTING

MODE_ZEMP1 = 'E'

EMPNO = 102.

  • X_EMPNO = ' '

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

Former Member
0 Kudos

Hi ,

There will be only 3 kinds of lock modes....

1)exclusive,cumulative

2)shared

3)exclusive,non cumulative

this in 4.6 version.....

is tht entire code which is there in ur program......

?

if u r locking the tbale means u might be doiing some changes to the table rite.....where u hav included that .....

try to sedn the entire code once.........

0 Kudos

hi

im just created a sample lock object to lock a table?

could u tell me the entire process.. How to create a lock object and how to call FM? explain one complete example?

Former Member
0 Kudos

Basically lock objects are used to lock any tables.....when we hav to perform some chaanges on tables....like deleting some records,adding some records,updating some recors in a table......so that no other users can access the table so that we can avoid data inconsistency.....

for EX:

1)if u r deleting one record and if the other user makes use of those recors.....then problems occurs.

2)If u r adding one record...and other user also trying to add some records to the table ...then data redundancy may occur.

So we lock our table before performing any operations on the table so that other users cannot access that table.

so first try to create a table in data dictionary with some records.

After that try this code in abap editor.....

this will add records to ur table...after executing this....some records gets added to ur table...check in DDIC.

The Table structure and ur internal table structure should be same.

see for example....in my table....i have MATNR ,ERSDA,ERNAM,LAEDA,AENAM,

i have entered some records initialli into the tabel....

after running this porgram....3 records added to the table when i have checked in the DDIC again.

REPORT ZTESTTAB9 .

TABLES:ZTESTTAB9.

*VARIABLES:

DATA:ITAB LIKE ZTESTTAB9 OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'ENQUEUE_EZTESTTAB9'

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.

ITAB-MATNR = '1004'.

ITAB-ERSDA = '10.10.2007'.

ITAB-ERNAM = 'GEETHA'.

ITAB-LAEDA = '10.10.2007'.

ITAB-AENAM = 'JYOTHI'.

APPEND ITAB.

MOVE ITAB TO ZTESTTAB9.

INSERT ZTESTTAB9.

ITAB-MATNR = '1005'.

ITAB-ERSDA = '10.10.2007'.

ITAB-ERNAM = 'MARY'.

ITAB-LAEDA = '10.10.2007'.

ITAB-AENAM = 'JYOTHI'.

APPEND ITAB.

MOVE ITAB TO ZTESTTAB9.

INSERT ZTESTTAB9.

ITAB-MATNR = '1006'.

ITAB-ERSDA = '10.10.2007'.

ITAB-ERNAM = 'SHIVA'.

ITAB-LAEDA = '10.10.2007'.

ITAB-AENAM = 'JYOTHI'.

APPEND ITAB.

MOVE ITAB TO ZTESTTAB9.

INSERT ZTESTTAB9.

CALL FUNCTION 'DEQUEUE_EZTESTTAB9'

.

WRITE:/ 'RECORD MOVED TO TABLE'.

Reward if Useful

Jyothi D.

Former Member
0 Kudos

Hi

through report program also we can set the lock like this


TABLES  sflight.

DATA  text(8) TYPE c.

DATA  ok_code TYPE sy-ucomm.

CALL SCREEN 100.

MODULE init OUTPUT.
  SET PF-STATUS 'BASIC'.
  sflight-carrid = 'LH'. sflight-connid = '400'.
ENDMODULE.

MODULE exit INPUT.
  LEAVE PROGRAM.
ENDMODULE.

MODULE enqueue INPUT.
  CASE ok_code.
    WHEN 'ENQUEUE'.
      CALL FUNCTION 'ENQUEUE_EDEMOFLHT'
           EXPORTING
                mode_sflight   = 'X'
                carrid         = sflight-carrid
                connid         = sflight-connid
                fldate         = sflight-fldate
           EXCEPTIONS
                foreign_lock   = 1
                system_failure = 2
                OTHERS         = 3.

      CASE sy-subrc.
        WHEN 0.
          MESSAGE i888 WITH 'Enqueue successful'(001).
        WHEN 1.
          text = sy-msgv1.
          MESSAGE e888 WITH 'Record already'(002) 'locked by'(003)
                                                   text.
          CALL TRANSACTION 'SM12'.
        WHEN 2 OR 3.
          MESSAGE e888 WITH 'Error in enqueue!'(004)
                            'SY-SUBRC:' sy-subrc.
      ENDCASE.
    WHEN 'DEQUEUE'.
      CALL FUNCTION 'DEQUEUE_EDEMOFLHT'
           EXPORTING
                mode_sflight = 'X'
                carrid       = sflight-carrid
                connid       = sflight-connid
                fldate       = sflight-fldate
           EXCEPTIONS
                OTHERS       = 1.
      CASE sy-subrc.
        WHEN 0.
          MESSAGE i888 WITH 'Dequeue successful'(005).
        WHEN 1.
          MESSAGE e888 WITH 'Error in dequeue!'(006).
      ENDCASE.
    WHEN 'SM12'.
      CALL TRANSACTION 'SM12'.
  ENDCASE.

ENDMODULE.

MODULE select INPUT.
  CASE ok_code.
    WHEN 'SELECT'.
      SELECT * FROM sflight WHERE carrid = sflight-carrid
                              AND connid = sflight-connid
                              AND fldate = sflight-fldate.
      ENDSELECT.
      MESSAGE i888 WITH 'SY-SUBRC:' sy-subrc.
  ENDCASE.
ENDMODULE.

reward if usefull