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 sequence

Former Member
0 Likes
619

Dear All expert,

I read a documment that metioned the sequence of update should be:

1. lock the related object.

2.select out the related data.

3.update the records

4.unlock the objects.

I think it correct to do it as this sequence.But my question is that how can I lock the related object before I select out them out?

Shall I lock all the related table?

Please reply and show me some sample code!!

4 REPLIES 4
Read only

Peter_Lintner
Participant
0 Likes
548

Hi!

To lock an object o have to use a enqueue function.

For standard objects there should be a standard enqueue function module.

For custom objects you should create this with the transaction se11.

You never should lock the table!

Please refer to the SAP-Help!

Kind regards

Peter

Read only

Former Member
0 Likes
548

hi,

for custom tables, you can create lock objects in se11 (in Ides : ESSPFLI - for spfli table).

once you have created that.

in your custom program, click on pattern, in fn module give Enqueue_ESSPFLI and it will get you the pattern

CALL FUNCTION 'ENQUEUE_ESSPFLI'
  EXPORTING
*    MODE_SPFLI           = 'E'
    MANDT                = SY-MANDT
    CARRID               = 'AA'
    CONNID               = '0101'
*    X_CARRID             = ' '
*    X_CONNID             = ' '
*    _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.
 CALL FUNCTION 'DEQUEUE_ESSPFLI'
  EXPORTING
*    MODE_SPFLI       = 'E'
    MANDT                = SY-MANDT
    CARRID               = 'AA'
    CONNID               = '0101' 
*    X_CARRID         = ' '
*    X_CONNID         = ' '
*    _SCOPE           = '3'
*    _SYNCHRON        = ' '
*    _COLLECT         = ' '
           .

We lock with the primary keys (so that only that particular record is locked)

Regards

Sajid

Read only

0 Likes
548

I can understand totally what your want to explain. The problem is that, before select how can you know the lock key's value?

If you lock it after selection, it maybe already changed by other users just when you are selecting!!

Read only

0 Likes
548

Hi Edward,

Table shuld not be locked instead

U should lock the record of the table .That can be done by using ENQUEUE_******* Function Module.

U need to pass the combination of primary keys for that particular record.

While locking the record if its locked by another user an exception will be triggered called foreign lock with which ur not able to lock it.

After doing so, chk it in tcode SM12 whether ur lock is successful or not.

The sequence which u mentioned for locking is fine.

Chk this thread .U will get clear idea.

Chk this documentation too

Link:[Lock Objects|http://help.sap.com/saphelp_nw04/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm]

Regards,

Lakshman.