REPORT ZPROCTIM.
*
*  This program sums the CPU time by workprocess type, and by
*  application server, consumed by the workprocesses.
*  It is useful, to help to balance the different
*  services between the servers.
*
INCLUDE .
DATA: DEST(8), TAIL(5), HEAD(5).
DATA: SAPS TYPE I, SALL TYPE I, T1 TYPE I, T2 TYPE I, T3 TYPE I,
T4 TYPE I, T5 TYPE I, T6 TYPE I.
DATA: WITH_CPU TYPE X VALUE 10.
DATA: 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 RES OCCURS 10,
      HOST(8), TYPE(3), TIME TYPE I,
END OF RES.
DATA: BEGIN OF RES2 OCCURS 10,
      TYPE(3), HOST(8), TIME TYPE I,
END OF RES2.

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.
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.
  RES-HOST = DEST. RES-TYPE = WPLIST-WP_TYP.
  SPLIT WPINFO-WP_CPU AT ':' INTO HEAD TAIL.
  RES-TIME = 60 * HEAD + TAIL.
  COLLECT RES.
ENDLOOP.
LOOP AT RES.
  AT NEW HOST.
    WRITE:  '         ' COLOR 2 NO-GAP,
            RES-HOST COLOR 2 NO-GAP,
            '    ' COLOR 2 NO-GAP.
  ENDAT.
ENDLOOP.
WRITE:  '       ' COLOR 2 NO-GAP,
        SYM_CUMULATED AS SYMBOL COLOR 2 NO-GAP,
        'appserv' COLOR 2 NO-GAP,
        '           ' COLOR 2 NO-GAP,
        SYM_CUMULATED AS SYMBOL COLOR 2 NO-GAP,
        'all     ' COLOR 2 NO-GAP.

LOOP AT RES.
  RES2-HOST = RES-HOST. RES2-TYPE = RES-TYPE. RES2-TIME = RES-TIME.
  APPEND RES2.
ENDLOOP.

SORT RES2 BY TYPE.
*reak-point.
LOOP AT RES2.
  AT NEW TYPE.
    WRITE: / RES2-TYPE COLOR 2.
  ENDAT.
  CASE RES2-HOST.
    WHEN '????'.
      WRITE 6 RES2-TIME.
      SALL = SALL + RES2-TIME.
      T3 = T3 + RES2-TIME.
    WHEN '????'.
      WRITE 26 RES2-TIME.
      SALL = SALL + RES2-TIME.
      SAPS = SAPS + RES2-TIME.
      T4 = T4 + RES2-TIME.
    WHEN '????'.
      WRITE 48 RES2-TIME.
      SALL = SALL + RES2-TIME.
      SAPS = SAPS + RES2-TIME.
      T5 = T5 + RES2-TIME.
    WHEN '????'.
      WRITE 69 RES2-TIME.
      SALL = SALL + RES2-TIME.
      SAPS = SAPS + RES2-TIME.
      T6 = T6 + RES2-TIME.
  ENDCASE.
  AT END OF TYPE.
    WRITE: 89 SAPS, 109 SALL.
    T1 = T1 + SALL. T2 = T2 + SAPS.
    SAPS = 0. SALL = 0.
  ENDAT.
ENDLOOP.
WRITE: / SYM_CUMULATED AS SYMBOL COLOR 2.
WRITE: 6 T3, 26 T4, 48 T5, 69 T6, 89 T2, 109 T1.