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 Object Implementation

Former Member
0 Likes
1,131

Hi Experts,

I need urgently to implement Lock object to avoid changing of Customer ID ( customized Feld from customized DB) from different users and programs ...

So to achieve this I have processed as follow:

  1. created lock object in se11
  2. gave the required Feld
  3. Call the lock function in the first Program.
CALL FUNCTION 'ENQUEUE_ZTABLE '     EXPORTING
      mode_Ztable = 'E'
      mandt               = sy-mandt
      Customer ID        = lv_Customer_ID 
*     X_Customer ID        = ' '
*     _SCOPE              = '2'
*     _WAIT               = ' '
*     _COLLECT            = ' '
    EXCEPTIONS
      foreign_lock        = 1
      system_failure      = 2
      OTHERS              = 3. 

4- The object has shown in T.cde SM12.

5- at the same time in the second program I have called the data depend on the locked customer_ID :

  • so calling is working
  • now updating the data
 
update Ztable set Ztable~Customer_ID = new_customer_id
                   where Customer_ID = lv_Customer_ID 
                                                                        
  • unfortunately, the record was successfully updated...

so why is not blocked and nothing sopped the process to say that this customer_id is already blocked by another user.

Even by deleting it will be deleted ...

your advice to achieve my requirement will be highly appreciated..

Best Regards

Khaled

6 REPLIES 6
Read only

raghug
Active Contributor
0 Likes
1,014

Try changing the scope and mode in your call.

Read only

Former Member
0 Likes
1,014

Hi Raghu,

Thanks for your comment,

Could you pls provide an example or a Link for implementation of Lock objects

Best Regards

Read only

matt
Active Contributor
1,014

You very urgently need to read about how the locking concept works. It does not prevent changes to the database. It does not work the way you think it does.

Read only

Former Member
0 Likes
1,014

Hi Matthew,

Thanks, it seems the Locking object will not serve my requirement directly, I used this call Function in the first/second Programs as well

CALL FUNCTION 'ENQUEUE_READ'
* EXPORTING

*   GCLIENT                     = SY-MANDT

*   GNAME                       = ' '

*   GARG                        = ' '

*   GUNAME                      = SY-UNAME

*   LOCAL                       = ' '

*   FAST                        = ' '

*   GARGNOWC                    = ' '

* IMPORTING

*   NUMBER                      =

*   SUBRC                       =

  TABLES

    enq                         =  lt_seqg3

* EXCEPTIONS

*   COMMUNICATION_FAILURE       = 1

*   SYSTEM_FAILURE              = 2

*   OTHERS                      = 3

          .

IF sy-subrc <> 0.



ENDIF.

then I will check the output table (lt_seqg3) first if she has any locked object which I need to call or delete then error msg. will be raised...

--- is there any better way to achieve this------

- Could you pls provide an example or a Link for implementation of Lock objects....

Best Regards.

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,014
Khaled Al Sharbaji You have done almost everything ; you might use ENQUEUE_READ to check if there's a lock, but you may also do the same check by calling ENQUEUE_ZTABLE with MODE_ZTABLE = 'V' (cf "check" lock modes), that checks if one Exclusive lock is set, without setting the lock.
Read only

former_member184158
Active Contributor
0 Likes
1,014

Hello Khaled Al Sharbaji,

at first you have to create a lock object to prevent another user to change your table when you change it. It prevent more than one to change the field at same time.

Create lock object

Or if you want to lock the table you can use CALL FUNCTION 'ENQUEUE_E_TABLE'

Lock & unlock table

Best regards

Ebrahim