Quantcast
Channel: ABAP Development
Viewing all articles
Browse latest Browse all 948

How to lock TMG only at Row level

$
0
0

I read somewhere

Walking on water and building code for requirements is very easy... As long as they are frozen .

 

We started with a requirement which needed a user to be able change the data in one of the custom tables .

 

Everything was tested and finalized for production when just a days from the Go live the business comes back and saying they need multiple users in in the TMG Transaction at the same time working on different sets of data.

 

We did not have the time to redesign the whole thing using editable ALV's.

Also I did not really want to go the ALV way as TMG has a more complete experience.

 

So that's when I decided to look into trying to make it lock at a record level instead of locking the complete table , with some help from the various other articles here's how we achieved it. ( thought it would be nice to document it for future use) .

 

  • Create the table and a Lock object , (this one had a big primary key) .

1.png

  • Create the TMG for it .

2.png

  • Make a note of the Function group used and the Screen number.

3.png

  • Navigate to the FG in SE80 .

4.png

 

  • Open the Screen and add a new Module( ZCUSTOM_ENQUE)  in the PBO section .

5.png

  • Put in the following code ( I prefer to create a  new include to store custom modules )
MODULE zcustom_enque OUTPUT.
*Call the function module corresponding to the lock object we created  CALL FUNCTION 'ENQUEUE_EZXXXXXXXXX'    EXPORTING      mode_ztpp_XXXXXX = 'E'      mandt            = sy-mandt      arbpl            = ztpp_xxxxxx-arbpl      matnr            = ztpp_xxxxxx-matnr      dtvon            = ztpp_xxxxxx-dtvon      werks            = ztpp_xxxxxx-werks      mdv01            = ztpp_xxxxxx-mdv01      srno             = ztpp_xxxxxx-srno      x_arbpl          = ' '      x_matnr          = ' '      x_dtvon          = ' '      x_werks          = ' '      x_mdv01          = ' '      x_srno           = ' '      _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.
* row is locked..hence gray..    LOOP AT SCREEN.      screen-input = 0.      MODIFY SCREEN.    ENDLOOP.  ENDIF.
ENDMODULE.                 " ZCUSTOM_ENQUE  OUTPUT 
  • Create a report program in SE38 ( this will be the entry point for the user )

7.png

  • The below Report ensures there are no locks at the table level when the TMG is called and should be the only call method for a TMG . ( assign a Tcode to this report ) .

 

REPORT  zpp_XXXXXXXXXXXXXXXX_tmg.
**Selection range for view maintenance
DATA:  BEGIN OF selekttab OCCURS 1.                INCLUDE STRUCTURE vimsellist.
DATA: END OF selekttab,
**Table of inactive CUA functions for view maintenance
BEGIN OF excl_cua_funct OCCURS 1.        INCLUDE STRUCTURE vimexclfun.
DATA: END 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 'ZTXXXXXX' .  " table name    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            = 'ZTXXXXXXXX' " TMG name     show_selection_popup = space  TABLES    dba_sellist          = selekttab    excl_cua_funct       = excl_cua_funct.

Hope this helps someone.


Amarpreet.


Viewing all articles
Browse latest Browse all 948

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>