Application Development 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: 

Can i lock & unlock Z table once on top & bottom, for a multiple updates?

former_member202077
Participant
0 Kudos

Hello,

We have a prog. in production, where in 2 custom Tables are updating (in a subroutine of 150 lines, say my_routine). Now, i have been asked to place the code for LOCKing the table & then UNLOCKING it, well. The exisitng code is as below,

FORM my_routine

1 - 20 lines some validations & data processing

21 st line - DELETE operation on z_table_1

22 - 30 some data processing

31st line - MODIFY operation on z_table_1

32 - 40 data processing

41st line - DELETE operation on z_table_2

like that......couple more DELETE operations, couple more MODIFY, couple more INSERT operations in this routine on 2 tables, at the end commit work as below

COMMIT WORK

ENDFORM.

Pls. let me know, now can I place LOCK & UNCLOCK on the beginning & End of the subroutine my_routine, i mean, just at one place as on top & on bottom instead of placing for each & every INSERT / DELETE / MODIFY statements, as below,

FORM my_routine

1 - 20 lines some validations & data processing


IF lv_delete_insert_modify_on_table_1 IS TRUE.
  LOCK the table_1
ENDIF.

IF lv_delete_insert_modify_on_table_2 IS TRUE.

  LOCK the table_2

ENDIF.

  

21 st line - DELETE operation on z_table_1

22 - 30 some data processing

31st line - MODIFY operation on z_table_1

32 - 40 data processing

41st line - DELETE operation on z_table_2

like that......couple more DELETE operations, couple more MODIFY, couple more INSERT operations in this routine

COMMIT WORK

IF lv_delete_insert_modify_on_table_1 IS TRUE.

  UN-LOCK the table_1

ENDIF.

  

IF lv_delete_insert_modify_on_table_2 IS TRUE.

  UN-LOCK the table_2

ENDIF.

  

ENDFORM.

Thank you

1 ACCEPTED SOLUTION

arindam_m
Active Contributor
0 Kudos

Hi,

It is advisable to just lock specific entries before MODIFY and INSERT operations, same applies for DELETE operations. Locking for longer periods is not advisable.

Cheers,

Arindam

7 REPLIES 7

arindam_m
Active Contributor
0 Kudos

Hi,

It is advisable to just lock specific entries before MODIFY and INSERT operations, same applies for DELETE operations. Locking for longer periods is not advisable.

Cheers,

Arindam

0 Kudos

Sorry i forgot to mention that, the both tables never else used, they are used only in this prog.

- Thank you    

arindam_m
Active Contributor
0 Kudos

Still its better.. not to lock it for such long time

Former Member
0 Kudos

Hi,

I know it is difficult put locking mechanism in these situations but Please try to pick all the data needed from table.

1. populate all the data you want to DELETE from Ztable into an internal table.

2. Modify all the data in the internal table.

Now within a single lock and unlock statement you can put two database operations one is to update the table using the second internal table and the other is to delete entries which are present in the first internal table.

In this way you will add some overhead in abap program which is acceptable, However you will reduce enormous database access you want to delete and modify statements.

Remember ultimately your objective is to reduce database accesses.

thanks,

Aswath. 

Former Member
0 Kudos

It is fine to lock just once going in and once coming out.  (So long as your code guarantees no duplicating entries.)  The thing that you have to remember however is that it is not a true DB lock (and can't be).  SAP creates artificial locks.  If another program is written that does not check the lock, then it will have full access whether the locks are set or not.

Neal

0 Kudos

as long as the table is not used and the response time of the db is Okay

its better not to lock for a long period but depends on your response time

you can do it

Better to do a test on it and trace the performance as well

st05 and trace it

0 Kudos

Ok, I need an explanation of why not to lock for a long time?