In most cases the process that checks a lock will need to place the lock as well. In most cases... What if you need to know whether something is locked without actually locking it ? E.g. you would like to update a table which acts like a process list of task list for another program. You may need to know whether this "other" program is currently running to process entries, to which you would like to respond by putting your entries in the process list with the "delayed" flag (key field) on. Here's an example lock with a read for this lock: (lock object E_EPROG
).
A small example report:
l_program_name = 'Z_PROGRAM_NAME'. CALL FUNCTION 'ENQUEUE_EPROG' EXPORTING PROGRAMM = l_program_name EXCEPTIONS OTHERS = 1.
The above lock can be read with:
l_program_name = 'Z_PROGRAM_NAME'. CALL FUNCTION 'ENQUEUE_READ' EXPORTING GCLIENT = SY-MANDT GNAME = 'TRDIR' GARG = l_program_name GUNAME = SPACE "Effectively: all users TABLES ENQ = i_enq EXCEPTIONS OTHERS = 1.
Result: you find out whether a lock is "out there" without actually locking it (relevant locks will be held on table i_ENQ
. One to remember: function module ENQUEUE_READ
.