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

table Locking & Unlocking for Z tables .

Former Member
0 Likes
2,470

Hi ,

if i create table and i want to do TABLE LOCKING & UNLOCKING based on the user then what i have to do .

gowri

1 ACCEPTED SOLUTION
Read only

Former Member
1,217

Hi ,

SAP provides you with the ability to restrict access to data while the table is being updated. This is fairly simple to implement via the use of a lock object (Created in SE11).



Step  1 - go to se11 ... last  option   for  lock object   create  button ,
assign  the table which  you want to do .

Step 2 - ABAP code to lock table entries
Add the following code in-order to create the table lock. This function module must be called before any 
update takes place. If a lock has already been taken out it will display the appropriate message. 
CALL FUNCTION 'ENQUEUE_EZ_ZTABLENAME'
      EXPORTING
           mode_ZTABLENAME = 'E'
           mandt              = sy-mandt
           KEYFIELD1           = "Value
           KEYFIELD2           = "Value
           KEYFIELD3           = "Value
                   ... 
*         X_KEYFIELD1            = ' '
*         X_KEYFIELD2            = ' '
*         X_KEYFIELD3            = ' '
                   ... 
*         _SCOPE             = '2'
*         _WAIT              = ' '
*         _COLLECT           = ' '
*   If exceptions are not used, message is displayed within FM
    EXCEPTIONS
         FOREIGN_LOCK       = 1
         SYSTEM_FAILURE     = 2
         OTHERS             = 3.
             
  IF sy-subrc <> 0.
*   Retrieve message displayed within Function Module
    message id     sy-msgid
              type   'I'
              number sy-msgno
              with   sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    EXIT.
  ENDIF.


Step 3  - ABAP code to Remove table lock(s)
The following code will remove the lock for the specific table entries.
CALL FUNCTION 'DEQUEUE_EZ_ZTABLENAME'
    EXPORTING
         MODE_ZTABLENAME = 'E'
         MANDT              = SY-MANDT
           mandt              = sy-mandt
           KEYFIELD1           = "Value
           KEYFIELD2           = "Value
           KEYFIELD3           = "Value
                   ... 
*         X_KEYFIELD1            = ' '
*         X_KEYFIELD2            = ' '
*         X_KEYFIELD3            = ' '
                   ...
*         _SCOPE             = '3'
*         _SYNCHRON          = ' '
*         _COLLECT           = ' '
          .

 

Here is the link with screen shots of it .

<a href="http://www.sapdev.co.uk/dictionary/lock_enqueue.htm">http://www.sapdev.co.uk/dictionary/lock_enqueue.htm</a>

Reward points if it is usefulll

Girish

Hi ,

if i create table and i want to do TABLE LOCKING & UNLOCKING based on the user then what i have to do .

gowri

1 REPLY 1
Read only

Former Member
1,218

Hi ,

SAP provides you with the ability to restrict access to data while the table is being updated. This is fairly simple to implement via the use of a lock object (Created in SE11).



Step  1 - go to se11 ... last  option   for  lock object   create  button ,
assign  the table which  you want to do .

Step 2 - ABAP code to lock table entries
Add the following code in-order to create the table lock. This function module must be called before any 
update takes place. If a lock has already been taken out it will display the appropriate message. 
CALL FUNCTION 'ENQUEUE_EZ_ZTABLENAME'
      EXPORTING
           mode_ZTABLENAME = 'E'
           mandt              = sy-mandt
           KEYFIELD1           = "Value
           KEYFIELD2           = "Value
           KEYFIELD3           = "Value
                   ... 
*         X_KEYFIELD1            = ' '
*         X_KEYFIELD2            = ' '
*         X_KEYFIELD3            = ' '
                   ... 
*         _SCOPE             = '2'
*         _WAIT              = ' '
*         _COLLECT           = ' '
*   If exceptions are not used, message is displayed within FM
    EXCEPTIONS
         FOREIGN_LOCK       = 1
         SYSTEM_FAILURE     = 2
         OTHERS             = 3.
             
  IF sy-subrc <> 0.
*   Retrieve message displayed within Function Module
    message id     sy-msgid
              type   'I'
              number sy-msgno
              with   sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    EXIT.
  ENDIF.


Step 3  - ABAP code to Remove table lock(s)
The following code will remove the lock for the specific table entries.
CALL FUNCTION 'DEQUEUE_EZ_ZTABLENAME'
    EXPORTING
         MODE_ZTABLENAME = 'E'
         MANDT              = SY-MANDT
           mandt              = sy-mandt
           KEYFIELD1           = "Value
           KEYFIELD2           = "Value
           KEYFIELD3           = "Value
                   ... 
*         X_KEYFIELD1            = ' '
*         X_KEYFIELD2            = ' '
*         X_KEYFIELD3            = ' '
                   ...
*         _SCOPE             = '3'
*         _SYNCHRON          = ' '
*         _COLLECT           = ' '
          .

 

Here is the link with screen shots of it .

<a href="http://www.sapdev.co.uk/dictionary/lock_enqueue.htm">http://www.sapdev.co.uk/dictionary/lock_enqueue.htm</a>

Reward points if it is usefulll

Girish