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

Reg:Lock concept

former_member197425
Active Participant
0 Likes
819

Hi,

Can anyone please tell me how to use Lock function module.That is I created a Lock object in se11 for a table and it generated two function modules.But the thing is how to use those function modules to lock that particular table?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
776

Hi,

Your lock object will create two FMs - ENQUEUE_<Lock Object> and DEQUEUE_<Lock Object>. The Enqueue FM should be called before you update or modify the database table for which the lock object is created. Once the necessary update is done, it should be dequeued.

If you want to lock the entire table, then do not select any lock parameter for the table.

Here is an example.

CALL FUNCTION 'ENQUEUE_<Lock Object>

EXPORTING

mode_<Lock Object> = 'E'

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

{ Work on the table and finally dequeue it}

CALL FUNCTION 'DEQUEUE_<Lock Object>'

EXPORTING

mode__<Lock Object> = 'E'.

Regards,

Sharmila

6 REPLIES 6
Read only

Former Member
0 Likes
776

hi Nandi,

It will generate two function modules i.e, ENQUEUE_EZ<TABLE> and DEQUEUE_EZ<TABLE> which you can find it in se37 ... just call ENQUEUE_EZ<TABLE> FM to lock the table before updating the table data and DEQUEUE_EZ<TABLE> to unlock after updating the table data ...

Regards,

Santosh

Read only

Former Member
0 Likes
776

hi,

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.

Read only

Former Member
0 Likes
777

Hi,

Your lock object will create two FMs - ENQUEUE_<Lock Object> and DEQUEUE_<Lock Object>. The Enqueue FM should be called before you update or modify the database table for which the lock object is created. Once the necessary update is done, it should be dequeued.

If you want to lock the entire table, then do not select any lock parameter for the table.

Here is an example.

CALL FUNCTION 'ENQUEUE_<Lock Object>

EXPORTING

mode_<Lock Object> = 'E'

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

{ Work on the table and finally dequeue it}

CALL FUNCTION 'DEQUEUE_<Lock Object>'

EXPORTING

mode__<Lock Object> = 'E'.

Regards,

Sharmila

Read only

Former Member
0 Likes
776

hi kishore,

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.

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.

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

Thanks & Regards,

Kalyan,

Reward points if usefull.

Read only

Former Member
0 Likes
776

Hi,

Lock object are use in SAP to avoid the inconsistancy at the time of data is being insert or modify into the database.

in SAP we have 3 lock objects

1)Read Lock

2)Write Lock

3)Enhanced write Lock

To create Lock object use T-Code SE11

when u create lock object system automatically creates 2 Function Modules

ENQUEUE_LOCKOBJECT NAME

DEQUEUE_LOCKOBJECT NAME

ENQUEUE_LOCKOBJECT NAME : To insert the object in a queue

DEQUEUE_LOCKOBJECT NAME :To remove the object.

Reward points if helpful

Thanks

Prashanth

Read only

Former Member
0 Likes
776

hi,

To synchronize simultaneous access by several users to the same data, the R/3 System provides a further locking mechanism in addition to database locking.

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.