REPORT ZUPDSTAT LINE-SIZE 164.
************************************************************************
* This is an example of how to dig out some interesting performance
* and statistical data from the STAT file. 
* The program creates a rank list of users based upon their database
* update and read activity. The results are the accumulated database 
* time and row number per user for the different categories:
* insert/delete/modify and sequential/direct read. The results can be
* sorted by any of these categories.
* There are a lot more interesting data in the STAT file that can
* be used to write similar programs.
************************************************************************
DATA: STATISTIC_VERSION_USED LIKE  SAPWLPSTRC-VERSION.
DATA: SORT_FIELD(20).

* General input parameters: from/to, client, STAT file path
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE T7.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) F1.
SELECTION-SCREEN POSITION 40.
PARAMETERS: FDAT LIKE SY-DATUM,
            FTIM LIKE SY-UZEIT.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) F2.
SELECTION-SCREEN POSITION 40.
PARAMETERS: TDAT LIKE SY-DATUM,
            TTIM LIKE SY-UZEIT.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) F4.
SELECTION-SCREEN POSITION 40.
PARAMETERS: CLI LIKE SY-MANDT.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(35) F3.
SELECTION-SCREEN POSITION 40.
PARAMETERS: FILE(128) LOWER CASE.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B1.

* Sort order input
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE T5.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) F5.
SELECTION-SCREEN POSITION 40.
PARAMETERS: ASC  RADIOBUTTON GROUP ORD,
            DESC RADIOBUTTON GROUP ORD.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B2.

* Sort criteria input
SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE T6.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) T1.
SELECTION-SCREEN POSITION 62.
PARAMETERS: A1 RADIOBUTTON GROUP SORT.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(55) T2.
SELECTION-SCREEN POSITION 62.
PARAMETERS: A2 RADIOBUTTON GROUP SORT.
PARAMETERS: A3 RADIOBUTTON GROUP SORT.
SELECTION-SCREEN POSITION 67.
PARAMETERS: A4 RADIOBUTTON GROUP SORT.
PARAMETERS: A5 RADIOBUTTON GROUP SORT.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(55) T3.
SELECTION-SCREEN POSITION 62.
PARAMETERS: A6 RADIOBUTTON GROUP SORT.
PARAMETERS: A7 RADIOBUTTON GROUP SORT.
SELECTION-SCREEN POSITION 67.
PARAMETERS: A8 RADIOBUTTON GROUP SORT.
PARAMETERS: A9 RADIOBUTTON GROUP SORT.
SELECTION-SCREEN POSITION 72.
PARAMETERS: AA RADIOBUTTON GROUP SORT.
PARAMETERS: AB RADIOBUTTON GROUP SORT.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(50) T4.
SELECTION-SCREEN POSITION 62.
PARAMETERS: AC RADIOBUTTON GROUP SORT.
PARAMETERS: AD RADIOBUTTON GROUP SORT.
SELECTION-SCREEN POSITION 67.
PARAMETERS: AE RADIOBUTTON GROUP SORT.
PARAMETERS: AF RADIOBUTTON GROUP SORT.
SELECTION-SCREEN POSITION 72.
PARAMETERS: AG RADIOBUTTON GROUP SORT.
PARAMETERS: AH RADIOBUTTON GROUP SORT.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B3.

*Internal tables
DATA: BEGIN OF V1_NORMAL_RECORDS OCCURS 100.
        INCLUDE STRUCTURE  SAPWLSTATR.
DATA: END OF V1_NORMAL_RECORDS.
DATA: BEGIN OF V2_NORMAL_RECORDS OCCURS 100.
        INCLUDE STRUCTURE  SAPWLPFNRM.
DATA: END OF V2_NORMAL_RECORDS.
DATA: BEGIN OF SUM OCCURS 100,
        ACCOUNT(12),
        READSEQREC TYPE I,
        READSEQTI TYPE I,
        READDIRREC TYPE I,
        READDIRTI TYPE I,
        UPDREC TYPE I,
        UPDTI TYPE I,
        DELREC TYPE I,
        DELTI TYPE I,
        INSREC TYPE I,
        INSTI TYPE I,
        SUM_RD_ROW TYPE I,
        SUM_RD_TIM TYPE I,
        SUM_MOD_ROW TYPE I,
        SUM_MOD_TIM TYPE I,
        SUM_ALL_ROW TYPE I,
        SUM_ALL_TIM TYPE I,
END OF SUM.

*Initialize the selection screen
INITIALIZATION.
  T1 = 'User Name'.
  T2 = 'READ: Sequential(row/time) Direct(row/time)'.
  T3 = 'Update(row/time) Delete(row/time) Insert(row/time)'.
  T4 = 'SUM: Read(row/time) Modify(row/time) All(row/time)'.
  T5 = 'Sort'.
  T6 = 'By'.
  T7 = 'Period, Client and STAT file'.

  F1 = 'From: (date/time)'.
  F2 = 'To: (date/time)'.
  F3 = 'STAT file path(only for old stat)'.
  F4 = 'Client'.
  F5 = 'Ascending/Descending'.

  FDAT = SY-DATUM. FTIM = SY-UZEIT.
  FDAT = FDAT - 1. TTIM = SY-UZEIT.
  TDAT = SY-DATUM.
  CLI = SY-MANDT.

* Write a page header
TOP-OF-PAGE.
  WRITE:        / 'User' COLOR 2,
             14(15) 'Sequential read' COLOR 2,
             30(15) 'Direct read' COLOR 2,
             46(15) 'Update' COLOR 2,
             62(15) 'Delete' COLOR 2,
             78(15) 'Insert' COLOR 2,
             94(15) 'Sum Read' COLOR 5,
             110(15) 'Sum Modify' COLOR 5,
             126(15) 'Sum All' COLOR 6.

  WRITE:        / 'name' COLOR 2,
            14(6) 'rows' COLOR 2,
            21(8) 'time(ms)' COLOR 2,
            30(6) 'rows' COLOR 2,
            37(8) 'time(ms)' COLOR 2,
            46(6) 'rows' COLOR 2,
            53(8) 'time(ms)' COLOR 2,
            62(6) 'rows' COLOR 2,
            69(8) 'time(ms)' COLOR 2,
            78(6) 'rows' COLOR 2,
            85(8) 'time(ms)' COLOR 2,
            94(6) 'rows' COLOR 5,
           101(8) 'time(ms)' COLOR 5,
           110(6) 'rows' COLOR 5,
           117(8) 'time(ms)' COLOR 5,
           126(6) 'rows' COLOR 6,
           133(8) 'time(ms)' COLOR 6.

* Main
START-OF-SELECTION.
* Figure out the sort field name
  IF A1 = 'X'.
    SORT_FIELD = 'ACCOUNT'.
  ELSEIF A2 = 'X'.
    SORT_FIELD = 'READSEQREC'.
  ELSEIF A3 = 'X'.
    SORT_FIELD = 'READSEQTI'.
  ELSEIF A4 = 'X'.
    SORT_FIELD = 'READDIRREC'.
  ELSEIF A5 = 'X'.
    SORT_FIELD = 'READDIRTI'.
  ELSEIF A6 = 'X'.
    SORT_FIELD = 'UPDREC'.
  ELSEIF A7 = 'X'.
    SORT_FIELD = 'UPDTI'.
  ELSEIF A8 = 'X'.
    SORT_FIELD = 'DELREC'.
  ELSEIF A9 = 'X'.
    SORT_FIELD = 'DELTI'.
  ELSEIF AA = 'X'.
    SORT_FIELD = 'INSREC'.
  ELSEIF AB = 'X'.
    SORT_FIELD = 'INSTI'.
  ELSEIF AC = 'X'.
    SORT_FIELD = 'SUM_RD_ROW'.
  ELSEIF AD = 'X'.
    SORT_FIELD = 'SUM_RD_TIM'.
  ELSEIF AE = 'X'.
    SORT_FIELD = 'SUM_MOD_ROW'.
  ELSEIF AF = 'X'.
    SORT_FIELD = 'SUM_MOD_TIM'.
  ELSEIF AG = 'X'.
    SORT_FIELD = 'SUM_ALL_ROW'.
  ELSEIF AH = 'X'.
    SORT_FIELD = 'SUM_ALL_TIM'.
  ENDIF.

  CALL FUNCTION 'SAPWL_STATREC_READ_FILE'
       EXPORTING
            READ_CLIENT            = CLI
            READ_END_DATE          = TDAT
            READ_END_TIME          = TTIM
            READ_START_DATE        = FDAT
            READ_START_TIME        = FTIM
            STATISTIC_FILE         = FILE
       IMPORTING
            STATISTIC_VERSION_USED = STATISTIC_VERSION_USED
       TABLES
            V1_NORMAL_RECORDS      = V1_NORMAL_RECORDS
            V2_NORMAL_RECORDS      = V2_NORMAL_RECORDS.

  LOOP AT V2_NORMAL_RECORDS.
    V2_NORMAL_RECORDS-READSEQTI = V2_NORMAL_RECORDS-READSEQTI / 1000.
    V2_NORMAL_RECORDS-READDIRTI = V2_NORMAL_RECORDS-READDIRTI / 1000.
    V2_NORMAL_RECORDS-UPDTI = V2_NORMAL_RECORDS-UPDTI  / 1000.
    V2_NORMAL_RECORDS-DELTI = V2_NORMAL_RECORDS-DELTI / 1000.
    V2_NORMAL_RECORDS-INSTI = V2_NORMAL_RECORDS-INSTI / 1000.
    MODIFY V2_NORMAL_RECORDS.
  ENDLOOP.

  LOOP AT V1_NORMAL_RECORDS.
    V1_NORMAL_RECORDS-READSEQTI = V1_NORMAL_RECORDS-READSEQTI / 1000.
    V1_NORMAL_RECORDS-READDIRTI = V1_NORMAL_RECORDS-READDIRTI / 1000.
    V1_NORMAL_RECORDS-UPDTI = V1_NORMAL_RECORDS-UPDTI  / 1000.
    V1_NORMAL_RECORDS-DELTI = V1_NORMAL_RECORDS-DELTI / 1000.
    V1_NORMAL_RECORDS-INSTI = V1_NORMAL_RECORDS-INSTI / 1000.
    MODIFY V1_NORMAL_RECORDS.
  ENDLOOP.

  LOOP AT V2_NORMAL_RECORDS.
    MOVE-CORRESPONDING V2_NORMAL_RECORDS TO SUM.
    COLLECT SUM.
  ENDLOOP.

  LOOP AT V1_NORMAL_RECORDS.
    MOVE-CORRESPONDING V1_NORMAL_RECORDS TO SUM.
    COLLECT SUM.
  ENDLOOP.

  LOOP AT SUM.
    SUM-SUM_RD_ROW  = SUM-READSEQREC + SUM-READDIRREC.
    SUM-SUM_RD_TIM  = SUM-READSEQTI + SUM-READDIRTI.
    SUM-SUM_MOD_ROW = SUM-UPDREC + SUM-DELREC + SUM-INSREC.
    SUM-SUM_MOD_TIM = SUM-UPDTI + SUM-DELTI + SUM-INSTI.
    SUM-SUM_ALL_ROW = SUM-SUM_RD_ROW + SUM-SUM_MOD_ROW.
    SUM-SUM_ALL_TIM = SUM-SUM_RD_TIM + SUM-SUM_MOD_TIM.
    MODIFY SUM.
  ENDLOOP.

  IF ASC = 'X'.
    SORT SUM BY (SORT_FIELD) ASCENDING.
  ELSE.
    SORT SUM BY (SORT_FIELD) DESCENDING.
  ENDIF.


  LOOP AT SUM.
    WRITE: /  SUM-ACCOUNT,
              14(7) SUM-READSEQREC,
              22(7) SUM-READSEQTI,
              30(7) SUM-READDIRREC,
              38(7) SUM-READDIRTI,
              46(7) SUM-UPDREC,
              54(7) SUM-UPDTI,
              62(7) SUM-DELREC,
              70(7) SUM-DELTI,
              78(7) SUM-INSREC,
              86(7) SUM-INSTI,
              94(7) SUM-SUM_RD_ROW,
             102(7) SUM-SUM_RD_TIM,
             110(7) SUM-SUM_MOD_ROW,
             118(7) SUM-SUM_MOD_TIM,
             126(7) SUM-SUM_ALL_ROW,
             134(7) SUM-SUM_ALL_TIM.
  ENDLOOP.