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 Objects

Former Member
0 Likes
900

Hi all,

Can anyone please answer me these quoestions :

1) Do we ever create lock objects to standard tables?

2) What exactly is the advantage of going to lock objects?

3) While creating lock objects what do we need to specify in the lock parameter tab ?

4) How do I use enqueue and dequeue functions in the se38 program to lock and unlock ztable.

If posible please forward me a sample program using these FM's.

Regards,

Varun.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
822

Hi Varun,

You can create lock object for standard tebles also,

Pleae go through this sap help .

<a href="http://help.sap.com/saphelp_nw04/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm">Lock Objects</a>

Lanka

6 REPLIES 6
Read only

Former Member
0 Likes
823

Hi Varun,

You can create lock object for standard tebles also,

Pleae go through this sap help .

<a href="http://help.sap.com/saphelp_nw04/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm">Lock Objects</a>

Lanka

Read only

0 Likes
822

Yes, you should always create lock object when updating a table. This ensures that your data is consistant.

Here is a sampel where I'm locking the record for finish date and plant, updating, and unlocking the record.




  data: xzcposeqnr type zcposeqnr.
  data: numeric_value(4) type n.

  clear p_seqnr.

* Apply lock to sequence control table
  call function 'ENQUEUE_EZCPOSEQNR'
       exporting
            mode_zcposeqnr = 'E'
            mandt          = sy-mandt
            pedtr          = p_pedtr
            pwwrk          = p_pwwrk
            _wait          = 'X'.

  clear xzcposeqnr.
  select single * from zcposeqnr into xzcposeqnr
                 where pedtr = p_pedtr
                   and pwwrk = p_pwwrk.
  if sy-subrc = 0.
    numeric_value = xzcposeqnr-seqnr + 1.
    xzcposeqnr-seqnr = numeric_value.
    modify zcposeqnr from xzcposeqnr.
  endif.

* Unlock table entry
  call function 'DEQUEUE_EZCPOSEQNR'
       exporting
            mode_zcposeqnr = 'E'
            mandt          = sy-mandt
            pedtr          = p_pedtr
            pwwrk          = p_pwwrk.

Regards,

Rich Heilman

Read only

0 Likes
822

The lock paramter tab, is where you defin what the key of the record is that you want to lock. A lot of times this is also the key of the table inself.

In my previous example, I mentioned that I am locking on finish date and plant, these are the fields in my lock parameters tab.

Regards,

Rich Heilman

Read only

0 Likes
822

Hi All,

I created a Ztable named zvlfa1. the fields are mandt,lifnr,name1,region,land,amount. I inserted some data also in to the table.Now in se11 I created a lock object named ezlock. In the primary table I have specified it as zvlfa1 and lock mode as exclusive,not cumulative.

In an se38 program I have the following code.

REPORT ZLOCK_PROGRAM.

CALL FUNCTION 'ENQUEUE_EZLOCK'

EXPORTING

MODE_ZVLFA1 = 'X'

MANDT = SY-MANDT

LIFNR = '234567'

X_LIFNR = ' '

_SCOPE = '2'

_WAIT = 'X'

_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_EZLOCK'

EXPORTING

MODE_ZVLFA1 = 'X'

MANDT = SY-MANDT

LIFNR = '234567'

X_LIFNR = ' '

_SCOPE = '3'

_SYNCHRON = ' '

_COLLECT = ' '

.

After I execute the program and go to se12 and select the value lifnr = 234567 and say display it gives me a short dump.Probably what could be the error ? Also one more thing when we do data transefr using call transaction or session method we do not lock standard tables then why should we lock when updating using a program ?

<b>the short dump says screen not found.</b>

Regards,

varun.

Message was edited by: varun sonu

Read only

0 Likes
822

HI all,

Forget about my previous query. Say If I lock a record using enqueue FM before I update that, Is there any way to ckeck that it has been locked ? How do I know That it has been locked ?

Regards,

Varun.

Read only

0 Likes
822

If sy-subrc = 0 after the call, then you have successfully achieved the lock, if sy-subrc <> 0, then you have not and someone else is probably locking.

Regard,s

Rich Heilman