The following ABL code uses
_Lock and
_File database schema tables to list all the users currently locking database table records along with the table names involved. A copy of the procedure is attached to this Article
ListUsersAndTheirLockedTables.p
- A Temp-Table is explicitly used as the _Lock table is heavily used by the underlying database locking functionality
- _Lock._Lock-Usr = ? means the VST lock "record" is currently not in use. Unused locks will all always be at the end of the table - there will not be a used "record" after the first one that reports unknowns. For further information refer to Article Why does the _Lock table have records where _Lock-Usr = ?
DEFINE TEMP-TABLE ttLock NO-UNDO
FIELD iUSER AS INTEGER
FIELD cName AS CHARACTER
FIELD rRECID AS INTEGER
FIELD iTABLE AS INTEGER
FIELD cTABLE AS CHARACTER
INDEX UserName cName ASCENDING.
FOR EACH _Lock WHERE
_Lock._Lock-Usr <> ? AND
_Lock._Lock-Recid <> ? NO-LOCK:
/* Comment the next two statements to list the locked records individually */
FIND FIRST ttLock WHERE ttLock.iUSER = _Lock._Lock-Usr AND ttLock.iTABLE = _Lock._Lock-Table NO-LOCK NO-ERROR.
IF AVAILABLE ttLock THEN NEXT.
CREATE ttLock.
ASSIGN
ttLock.iUSER = _Lock._Lock-Usr
ttLock.cName = _Lock._Lock-Name
ttLock.rRECID = _Lock._Lock-Recid
ttLock.iTABLE = _Lock._Lock-Table.
END.
FOR EACH ttLock NO-LOCK:
FIND FIRST _File WHERE _File._File-Number = iTABLE NO-LOCK NO-ERROR.
ASSIGN
cTABLE = _File._File-Name.
DISPLAY
ttLock.iUSER LABEL "User Number"
ttLock.cName LABEL "User Name"
ttLock.cTABLE LABEL "Table Name".
END.