REPORT ZENQLIST NO STANDARD PAGE HEADING.
***********************************************************************
* Continuously display the rejected lock requests
* Useful tool to detect bottlenecks on particular tables
***********************************************************************
DATA: ENQ_LOCATION(70), LASTLINE TYPE I, FIRSTLINE TYPE I, FLAG TYPE I,
OLDLINE(200).
DATA: BEGIN OF LINE_TBL OCCURS 0.
        INCLUDE STRUCTURE SPFLIST.
DATA: END OF LINE_TBL.
DATA: BEGIN OF RES_TBL OCCURS 0.
        INCLUDE STRUCTURE SPFLIST.
DATA: END OF RES_TBL.
DATA: BEGIN OF ITAB OCCURS 5.
        INCLUDE STRUCTURE THLINES.
DATA: END OF ITAB.
*
START-OF-SELECTION.
* Status for safe exit:
  SET PF-STATUS 'SAFESTOP'.
* Figure out the location of the ENQLOG
* Start the enq logging
  CALL 'C_ENQUEUE' ID 'OPCODE' FIELD 'X'.
  CALL FUNCTION 'Z_ENQUEUE_DELAY'
         STARTING NEW TASK 'WAIT'
         PERFORMING WHEN_FINISHED ON END OF TASK.
  WRITE: ''.
*
AT USER-COMMAND.
  IF SY-UCOMM = 'SAFE'.
* Stop the enque logging and exit
    CALL 'C_ENQUEUE' ID 'OPCODE' FIELD 'Y'.
    SET SCREEN 0.
    LEAVE SCREEN.
  ENDIF.
  SY-LSIND = SY-LSIND - 1.
  CALL FUNCTION 'TH_REQUEST_QUEUE'
       TABLES
            REQUEST_QUEUES = ITAB.
* Read and display the enqlog file
  CALL FUNCTION 'ENQUEUE_READ_LOG'
       TABLES
            LOGLINES = LINE_TBL
       EXCEPTIONS
            OTHERS   = 1.
* Display the last 25 entries
  FLAG = 0.
  CLEAR RES_TBL. REFRESH RES_TBL.
  LOOP AT LINE_TBL.
    IF LINE_TBL CS 'SLEEP'.
      FLAG = 1.
    ELSE.
      IF FLAG = 0 AND LINE_TBL CS 'Rejected'.
        RES_TBL = OLDLINE.
        APPEND RES_TBL.
      ELSE.
        OLDLINE = LINE_TBL.
        DELETE LINE_TBL.FLAG = 0.
      ENDIF.
    ENDIF.
  ENDLOOP.
*
  WRITE: / 'List of the last 25 rejected lock requests'.
  WRITE: / SY-DATUM, SY-UZEIT.
  SKIP.
  DESCRIBE TABLE RES_TBL LINES LASTLINE.
  FIRSTLINE = LASTLINE - 25.
  IF FIRSTLINE <= 1. FIRSTLINE = 1. ENDIF.
  IF LASTLINE > FIRSTLINE.
    LOOP AT RES_TBL FROM FIRSTLINE TO LASTLINE.
      WRITE: / RES_TBL-LINE.
    ENDLOOP.
  ENDIF.
*
  CALL FUNCTION 'Z_ENQUEUE_DELAY'
       STARTING NEW TASK 'INFO'
       PERFORMING WHEN_FINISHED ON END OF TASK.
*
FORM WHEN_FINISHED USING TASKNAME.
  RECEIVE RESULTS FROM FUNCTION 'Z_ENQUEUE_DELAY'.
  SET USER-COMMAND 'BUMM'.
ENDFORM.