Row level locking of database table

By Swetabh Shukla, Infosys Technologies

Normally if a person opens table maintenance generator and tries to maintain the table, no one else can maintain the same table at the same time. This is because of table level lock by default in SAP. Only one user can maintain any table at a time through SM30 or any transaction that calls table maintenance generator. In the tutorial below we will see how to remove table level lock and apply row level lock. This way any number of users can modify the table at same time. But any particular row can be modified by only one user at a time. We will create a transaction for this purpose. The transaction will call our custom report. This custom report will call the table maintenance generator of the table after deleting table level lock. 

In current example let’s create following: 

Report: ZREP_SHUKS3

Transaction: ZTEST_SHUKS3

Table: ZTEST_SHUKS3 with table maintenance generator. 

Using transaction ZTEST_SHUKS3 we will delete the table level lock and put row level lock so that multiple users can maintain table at same time. Rows locked by one user will not be editable by other user. 

1.       Create table ZTEST_SHUKS3.                 

2.       Create table maintenance generator for the table. 

We will make single screen maintenance for this table. Save it. So finally we have table maintenance code automatically generated in function group ZTEST_SHUKS3. 

3.       Create lock object EYTSS_E433SH in SE11. Give it name as EZTEST_SHUKS3. 

 

 

Now save and activate the Lock object. SAP creates two function modules corresponding to lock object for enqueue and dequeue of the table. 

 

4.       Now create a report  ZREP_SHUKS3 and transaction code ZTEST_SHUKS3  to call this report. This tcode will call table maintenance generator of table ZTEST_SHUKS3 . 

5.       Normally if a person opens table maintenance generator and tries to maintain the table, no one else can maintain table at the same time. This is because of table level lock by default in SAP. Only one user can maintain any table at a time. In report ZREP_SHUKS3 we will delete the table level lock and put row level lock so that multiple users can maintain table at same time. Rows locked by one user will not be editable by other user. Check the report and comments given below. 

*&---------------------------------------------------------------------*
*& Report  ZREP_SHUKS3
*&
*&---------------------------------------------------------------------
*& Author : Swetabh Shukla
*& Date : 05/22/2009
*& Description : To delete table level lock from table.
*&---------------------------------------------------------------------*
REPORT  zrep_shuks3.

**Selection range for view maintenance
DATA:
  
BEGIN OF selekttab OCCURS 1.         "Selektionsbereich
        
INCLUDE STRUCTURE vimsellist.
DATAEND OF selekttab,

**Table of inactive CUA functions for view maintenance
BEGIN OF excl_cua_funct OCCURS 1.    "inaktive CUA-Fkt bei View-Pflege
        
INCLUDE STRUCTURE vimexclfun.
DATAEND OF excl_cua_funct.

DATA: lt_enq_del TYPE STANDARD TABLE OF seqg3,
      lt_enq_read 
TYPE STANDARD TABLE OF seqg7,
      lw_enq_read 
TYPE seqg7,
      lw_enq_del 
TYPE seqg3,
      lv_subrc 
TYPE sy-subrc.

*Read all the lock details in system
CALL FUNCTION 'ENQUE_READ2'
  
EXPORTING
    gclient = sy-mandt
    gname   = 
' '
    guname  = 
'*'
  
TABLES
    enq     = lt_enq_read.

*We will search entry for table level lock for our table
LOOP AT lt_enq_read INTO lw_enq_read
 
WHERE gname EQ 'RSTABLE'
 
AND   garg CS 'ZTEST_SHUKS3'.
  
MOVE-CORRESPONDING lw_enq_read TO lw_enq_del.
  
APPEND lw_enq_del TO lt_enq_del.
ENDLOOP.

*Delete table level lock entry for our table
CALL FUNCTION 'ENQUE_DELETE'
  
EXPORTING
    check_upd_requests = 
1
  
IMPORTING
    subrc              = lv_subrc
  
TABLES
    enq                = lt_enq_del.

*Now call the table maintenace generator.
CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
  
EXPORTING
    action               = 
'U'
    view_name            = 
'ZTEST_SHUKS3'
    show_selection_popup = 
'X'
  
TABLES
    dba_sellist          = selekttab
    excl_cua_funct       = excl_cua_funct.

Click here to continue...

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image