*
* This program creates a sequential file of long running ABAPs.
* Later, with the ZHEAVYLS program, we can figure out the
* "heavy" ABAPs of a given period of time, by interpreting the
* sequential file.
* The program creates a snapshot every 5 minutes, of the workpocesses
* on the different app. servers and db. server, running ABAPs 
* longer then 5 minutes. 
*
REPORT ZHEAVYPR.

DATA: OUTPUT_FILE(40) VALUE '/oracle/SID/sapreorg/heavy_abaps'.
DATA: DEST(8).DATA: WITH_CPU TYPE X VALUE 10,
        SRVNAME LIKE SPFID-APSERVER.
DATA: BEGIN OF SRV_TBL OCCURS 100.
        INCLUDE STRUCTURE MSXXLIST.
DATA  END OF SRV_TBL.
DATA: BEGIN OF WPLIST OCCURS 30.
        INCLUDE STRUCTURE WPINFOS.
DATA: END OF WPLIST.
DATA: BEGIN OF LOC_WPLIST OCCURS 30.
        INCLUDE STRUCTURE WPINFO.
DATA: END OF LOC_WPLIST.
DATA: BEGIN OF WPINFO OCCURS 30.
        INCLUDE STRUCTURE WPINFO.
DATA: END OF WPINFO.
DATA: BEGIN OF PFNORM OCCURS 30.
        INCLUDE STRUCTURE PFNORM.
DATA: END OF PFNORM.
DATA: BEGIN OF O,
1(10), 2(8), 3(8), 4(3), 5(8), 6(8),
END OF O.


CALL FUNCTION 'TH_SERVER_LIST' DESTINATION '????????'
     TABLES
          LIST = SRV_TBL.

REFRESH WPLIST.
LOOP AT SRV_TBL.
  SRVNAME = SRV_TBL-NAME.
  REFRESH LOC_WPLIST.
  WITH_CPU = 1.
  CALL FUNCTION 'TH_WPINFO' DESTINATION '???????'
       EXPORTING
            SRVNAME = SRVNAME
       TABLES
            WPLIST  = LOC_WPLIST
       EXCEPTIONS
            OTHERS  = 1.
  IF SY-SUBRC = 0.
    LOOP AT LOC_WPLIST.
      MOVE-CORRESPONDING LOC_WPLIST TO WPLIST.
      WPLIST-APSERVER = SRVNAME.
      APPEND WPLIST.
    ENDLOOP.
  ENDIF.
ENDLOOP.
OPEN DATASET OUTPUT_FILE FOR APPENDING IN TEXT MODE.
LOOP AT WPLIST.
  DEST = WPLIST-APSERVER.

  CALL FUNCTION 'TH_WP_DETAIL_INFO' DESTINATION DEST
      EXPORTING
            WP = WPLIST-WP_NO
            WITH_CPU = WITH_CPU
       IMPORTING
            WPINFO = WPINFO
            PFNORM = PFNORM.
  IF  NOT WPINFO-WP_REPORT IS INITIAL AND WPINFO-WP_ELTIME > 310.
*   write: / sy-datum no-gap, sy-uzeit, dest, ' ',wplist-wp_typ, ' ',
*          wpinfo-wp_eltime, ' ',  wpinfo-wp_report.
    O-1 = SY-DATUM. O-2 = SY-UZEIT.
    O-3 = DEST. O-4 = WPLIST-WP_TYP.
    O-5 = WPINFO-WP_ELTIME. O-6 = WPINFO-WP_REPORT.
    TRANSFER O TO OUTPUT_FILE.
  ENDIF.
ENDLOOP.
CLOSE DATASET OUTPUT_FILE.