07-26-2013 12:35 PM
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
07-26-2013 12:52 PM
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
07-26-2013 12:52 PM
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
07-26-2013 2:14 PM
Sorry i forgot to mention that, the both tables never else used, they are used only in this prog.
- Thank you
07-26-2013 2:18 PM
07-26-2013 1:18 PM
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.
07-26-2013 2:22 PM
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
07-26-2013 2:28 PM
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
07-26-2013 2:30 PM