Skip to end of metadata
Go to start of metadata

Author: Frank Buchholz
Submitted: 16.10.2009
Did you ever have struggled with the complicated list output of the authorization trace, transaction ST01?

Well, in this case you might love this small Report ZSHOWAUTHTRACE which reads the current trace file and shows the authorization trace data in a simple to use grid format. 

Features:

  1. Switch on/off the authorization trace.
    If you do not want to use this option you can deactivate the program lines between the following markers (3 blocks):
    * ### Begin of activation/deactivation of the trace
    * ### End of activation/deactivation of the trace
  2. Read trace file and filter events by user, authorization object or result.
    You can suppress duplicate authorization trace records if you want to create a unique list of authorization checks.
  3. Show trace file in grid format. You can use the standard sorting and filtering functions of the grid control. In addition you can copy the data or export it to a flat file.
  4. Navigate to the ABAP source code of the corresponding AUTHORITY-CHECK statement respective to the ABAP statement which performs the authorization check internally (like OPEN DATASET).

I've tested the report as of basis release 6.20. Currently it doesn't work in 4.6C.

In the meantime you can get the same functionality within standard transaction STAUTHTRACE in systems running SAP_BASIS 7.03 or higher. Here are the major notes describing this transactions and it's extensions:

Note 1631929 Using trace evaluation to maintain menus and authorizations
Note 1603756 Using StAuthTrace to record authorization checks
Note 1707841 STAUTHTRACE: System-wide trace evaluation
Note 1718059 New functions for the trace evaluation
Note 1745172 SU24: Import of authorization objects from system trace

Schönen Gruß / Kind regards
Frank Buchholz
SAP Active Global Support - Security Services


Report ZSHOWAUTHTRACE

2009-11-20 Additional button for analysis; Value help showing active users; Authorization check corrected; Minor improvements
2009-11-15 Initial version

Attachment: ZSHOWAUTHTRACE

You can adjust the text symbols automatically if you want to translate them.
Selection Texts:

DATEFROM

Date from

DATETO

Date to

MAX_REC

Max. count of records to read

SKIP_DUP

Suppress duplicate records

S_OBJ

Authorization object

S_RC

Return code

S_TCODE

Transaction

S_USER

User

TIMEFROM

Time from

TIMETO

Time to

USERNAME

User

*&---------------------------------------------------------------------*
*& Report  ZSHOWAUTHTRACE
*& Show ST01 authorization trace
*&---------------------------------------------------------------------*
*& creaded by:
*& Frank Buchholz
*& SAP Active Global Support - Security Services
*&
*& Version history
*& 2009-11-20 Additional button for analysis
*&            Value help showing active users
*&            Authorization check corrected
*&            Minor improvements
*& 2009-11-15 Initial version
*&---------------------------------------------------------------------*

REPORT  zshowauthtrace
  LINE-SIZE 255.

TYPE-POOLS: slis.                                     "Necessary for ALV
TYPE-POOLS: icon.

TABLES sscrfields.

SELECTION-SCREEN BEGIN OF LINE.
* ### Begin of activation/deactivation of the trace
SELECTION-SCREEN PUSHBUTTON 1(80)  but1 USER-COMMAND cli1 VISIBLE LENGTH 12.
SELECTION-SCREEN PUSHBUTTON 15(80) but2 USER-COMMAND cli2 VISIBLE LENGTH 12.
* ### End of activation/deactivation of the trace
SELECTION-SCREEN PUSHBUTTON 29(80) but3 USER-COMMAND onli VISIBLE LENGTH 12.
SELECTION-SCREEN COMMENT 45(60) tracetxt.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN SKIP.

SELECTION-SCREEN BEGIN OF BLOCK s_read WITH FRAME TITLE readtext.
PARAMETERS username TYPE xubname.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(31) fromtext.
PARAMETERS datefrom TYPE dats.
PARAMETERS timefrom TYPE tims.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(31) totext.
PARAMETERS dateto   TYPE dats.
PARAMETERS timeto   TYPE tims.
SELECTION-SCREEN END OF LINE.
PARAMETERS max_rec TYPE i DEFAULT 10000.
SELECTION-SCREEN END OF BLOCK s_read.

*SELECTION-SCREEN SKIP.

SELECTION-SCREEN BEGIN OF BLOCK s_sel WITH FRAME TITLE seltext.
DATA: x_user  TYPE xubname,
      x_tcode TYPE tcode,
      x_obj   TYPE agobject,
      x_rc    TYPE i.
SELECT-OPTIONS: s_user  FOR x_user,
                s_tcode FOR x_tcode,
                s_obj   FOR x_obj,
                s_rc    FOR x_rc.
PARAMETERS skip_dup AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK s_sel.

DATA: swb          LIKE tst21,
      sw_val(1)    TYPE c.

DATA: rectype      LIKE  trsqlrec-rectype,
      block_head   TYPE  trblhdrec,
      block_head0  TYPE  trblhdrec,
      auth_rec     TYPE  trauthrec,
      string1      TYPE  string.

DATA: lv_date       TYPE d,
      lv_time(8),
      lv_millis     TYPE n LENGTH 3,
      lv_timestamp(12).

DATA: g_repid      LIKE sy-repid,
      ls_fieldcat  TYPE slis_fieldcat_alv,
      lt_fieldcat  TYPE slis_t_fieldcat_alv,
      ls_layout    TYPE slis_layout_alv,
      ls_event     TYPE slis_alv_event,
      lt_events    TYPE slis_t_event,
      ls_prnt      TYPE slis_print_alv.

DATA: BEGIN OF ls_outtab,
        date       TYPE d,
        timestamp(12),                      "hh:mm:ss,mmm
        client     LIKE block_head0-client, "hidden
        username   LIKE block_head0-username,
        tcode      LIKE block_head0-tcode,
        abapprog   LIKE auth_rec-abapprog,  "hidden
        abappos    LIKE auth_rec-abappos,   "hidden
        rc         TYPE i, "LIKE auth_rec-reslt, RC = auth_rec-reslt * 4
        object     LIKE auth_rec-object,
        field1     TYPE agrfield,
        val1       TYPE agval,
        field2     TYPE agrfield,
        val2       TYPE agval,
        field3     TYPE agrfield,
        val3       TYPE agval,
        field4     TYPE agrfield,
        val4       TYPE agval,
        field5     TYPE agrfield,
        val5       TYPE agval,
        field6     TYPE agrfield,
        val6       TYPE agval,
        field7     TYPE agrfield,
        val7       TYPE agval,
        field8     TYPE agrfield,
        val8       TYPE agval,
        field9     TYPE agrfield,
        val9       TYPE agval,
        field10    TYPE agrfield,
        val10      TYPE agval,
        color      TYPE slis_t_specialcol_alv,
      END OF ls_outtab,
      lt_outtab LIKE TABLE OF ls_outtab.

DATA : ls_color TYPE slis_specialcol_alv.

DATA: max_rec_reached(1).

*----------------------------------------------------------------------*

INITIALIZATION.

  readtext = 'Select options for record selection'(020).
  seltext  = 'Select options for output'(008).

  fromtext = 'From time stamp'(009).
  datefrom = sy-datum.
  timefrom = sy-uzeit - 3600.                               " 1 hour
  totext   = 'To time stamp'(010).
  dateto   = sy-datum.
  timeto   = sy-uzeit.

* ### Begin of activation/deactivation of the trace
  CALL FUNCTION 'ICON_CREATE'
    EXPORTING
      name   = icon_activate
      text   = 'Activate'(001)
      info   = 'Activate authorization trace'(002)
    IMPORTING
      result = but1
    EXCEPTIONS
      OTHERS = 0.

  CALL FUNCTION 'ICON_CREATE'
    EXPORTING
      name   = icon_deactivate
      text   = 'Deactivate'(003)
      info   = 'Dectivate authorization trace'(004)
    IMPORTING
      result = but2
    EXCEPTIONS
      OTHERS = 0.
* ### End of activation/deactivation of the trace

  CALL FUNCTION 'ICON_CREATE'
    EXPORTING
      name   = icon_read_file
      text   = 'Analysis'(018)
      info   = 'Analysis authorization trace'(019)
    IMPORTING
      result = but3
    EXCEPTIONS
      OTHERS = 0.

*----------------------------------------------------------------------*

AT SELECTION-SCREEN OUTPUT.

  CALL 'C_GET_SWITCH' ID 'NAME' FIELD 'ANY   '
                      ID 'SW'   FIELD sw_val.
  IF sw_val = 'X'.
    CALL 'C_GET_SWITCH' ID 'NAME' FIELD 'AUTH  '
                        ID 'SW'   FIELD sw_val.
    IF sw_val = 'X'.
      tracetxt = 'Authorization trace is activated'(005).
    ELSE.
      tracetxt = 'Other trace is activated'(006).
    ENDIF.
  ELSE.
    tracetxt = 'Trace is deactivated'(007).
  ENDIF.
  concatenate tracetxt 'on'(021) sy-host
    into tracetxt SEPARATED BY space.

*----------------------------------------------------------------------*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR username.
* Show active users of host (see transaction SM04)

  DATA: ls_uinfo   TYPE          uinfo,
        lt_uinfo   TYPE TABLE OF uinfo.
*      ls_USRINFO type          USRINFO,
*      lt_USRINFO type table of USRINFO.

  DATA: l_repid       TYPE sy-repid,
        l_dynnr       TYPE sy-dynnr,
        l_window_title(40),
        ls_ulist      TYPE          uinfo-bname,
        lt_ulist      TYPE TABLE OF uinfo-bname,
        ls_field_tab  TYPE          dfies,
        lt_field_tab  TYPE TABLE OF dfies.

  CALL FUNCTION 'TH_USER_LIST'
    TABLES
      list    = lt_uinfo
*     USRLIST =  lt_USRINFO
    .

  DELETE lt_uinfo WHERE mandt NE sy-mandt.
  SORT lt_uinfo BY bname.
  DELETE ADJACENT DUPLICATES FROM lt_uinfo COMPARING bname.

  clear lt_ulist[].
  LOOP AT lt_uinfo INTO ls_uinfo.
    ls_ulist = ls_uinfo-bname.
    APPEND ls_ulist TO lt_ulist.
  ENDLOOP.

  CLEAR: ls_field_tab, lt_field_tab[].
  ls_field_tab-tabname   = 'UINFO'.
  ls_field_tab-fieldname = 'BNAME'.
  APPEND ls_field_tab TO lt_field_tab.
  l_repid = sy-repid.
  l_dynnr = sy-dynnr.
  concatenate 'Active users on'(024) sy-host
    into l_window_title separated by space.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
*     DDIC_STRUCTURE         = 'UINFO'
      retfield               = 'BNAME'
*     PVALKEY                = ' '
      dynpprog               = l_repid
      dynpnr                 = l_dynnr
      dynprofield            = 'USERNAME'
*     STEPL                  = 0
      window_title           = l_window_title
*     VALUE                  = ' '
      value_org              = 'C' " 'S'
*     MULTIPLE_CHOICE        = ' '
*     DISPLAY                = ' '
*     CALLBACK_PROGRAM       = ' '
*     CALLBACK_FORM          = ' '
*     CALLBACK_METHOD        =
*     MARK_TAB               =
*   IMPORTING
*     USER_RESET             =
      TABLES
      value_tab              = lt_ulist
      field_tab              = lt_field_tab
*     RETURN_TAB             =
*     DYNPFLD_MAPPING        =
    EXCEPTIONS
      parameter_error        = 1
      no_values_found        = 2
      OTHERS                 = 3
            .
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

*----------------------------------------------------------------------*
AT SELECTION-SCREEN.

* ### Begin of activation/deactivation of the trace
  CASE sscrfields.

    WHEN 'CLI1'.
*     Same authorization check like in ST01
      AUTHORITY-CHECK OBJECT 'S_ADMI_FCD'
                      ID     'S_ADMI_FCD'
                      FIELD  'ST0M'.
      IF sy-subrc <> 0.
        MESSAGE e053(tc).
      ENDIF.

      datefrom = sy-datum.
      timefrom = sy-uzeit.
      dateto   = sy-datum.
      timeto   = sy-uzeit.

      CLEAR swb.
      swb-client  = sy-mandt.
      swb-fuser   = username.
      swb-sw_any  = 'X'.
      swb-sw_auth = 'X'.
      PERFORM update_swb(rstrac25) USING swb.

    WHEN 'CLI2'.
*     Same authorization check like in ST01
      AUTHORITY-CHECK OBJECT 'S_ADMI_FCD'
                      ID     'S_ADMI_FCD'
                      FIELD  'ST0M'.
      IF sy-subrc <> 0.
        MESSAGE e053(tc).
      ENDIF.

      dateto   = sy-datum.
      timeto   = sy-uzeit.

      CLEAR swb.
      swb-client  = sy-mandt.
      swb-fuser   = username.
      PERFORM update_swb(rstrac25) USING swb.

  ENDCASE.
* ### End of activation/deactivation of the trace

*----------------------------------------------------------------------*

START-OF-SELECTION.

* Same authorization check like in ST01
  AUTHORITY-CHECK OBJECT 'S_ADMI_FCD'
                  ID     'S_ADMI_FCD'
                  FIELD  'ST0R'.
  IF sy-subrc <> 0.
    MESSAGE e053(tc).
  ENDIF.

* Close log file just to be sure... (see include RSTRAC22)
  CALL FUNCTION 'RSTR_CLOSE_FILE'
    EXCEPTIONS
      OTHERS = 1.

  IF max_rec <= 0.
    max_rec = 10000.
  ENDIF.

* Open trace file
  CALL FUNCTION 'RSTR_OPEN_FILE'
    EXPORTING
*     FILENAME          =
      date              = datefrom
      time              = timefrom
      enddate           = dateto
      endtime           = timeto
      username          = username
      client            = sy-mandt
*     TCODE             =
*     TRANS_ID          =
*     WPID              =
*     MIN_DURATION      =
*     TABLELIST         =
*     READ_SQL          =
      read_auth         = 'X'
*     READ_ENQUE        =
*     READ_RFC          =
*     READ_CMOD         =
*     READ_USER         =
*     READ_TBUF         =
*     EPP_ROOT_ID       =
*     EPP_CONNECTION_ID =
*     READ_HTTP         =
    EXCEPTIONS
      open_error        = 1
      invalid_parameter = 2
      parameter_missing = 3
      internal_error    = 4
      no_memory         = 5
      already_open      = 6
      end_of_file       = 7
      OTHERS            = 8.
  IF sy-subrc <> 0.
    CASE sy-subrc.
      WHEN 1.
        MESSAGE i030(tc).
      WHEN 6.
        MESSAGE i032(tc).
      WHEN OTHERS.
        MESSAGE i031(tc).
    ENDCASE.
    EXIT.
  ENDIF.

  DO.
    IF sy-index > max_rec.
      max_rec_reached = 'X'.
      EXIT.
    ENDIF.

*   Read next trace record
    CALL FUNCTION 'RSTR_READ_TRACE_REC'
*    EXPORTING
*      FILENAME                   =
*      DATE                       =
*      TIME                       =
*      ENDDATE                    =
*      ENDTIME                    =
*      USERNAME                   =
*      CLIENT                     =
*      MIN_DURATION               =
*      TABLISTFUNC                =
*      TABLELIST                  =
*      READ_SQL                   =
*      READ_AUTH                  =
*      READ_ENQUE                 =
*      READ_RFC                   =
*      READ_CMOD                  =
*      READ_USER                  =
*      READ_TBUF                  =
*      READ_HTTP                  =
      IMPORTING
        rectype                    = rectype
        block_head                 = block_head
*      SQL_REC                    =
        auth_rec                   = auth_rec
*      ENQUE_REC                  =
*      RFC_REC                    =
*      CMOD_REC                   =
*      USER_REC                   =
*      TBUF_REC                   =
        string1                    = string1
*      STRING2                    =
*      BUFFER_OBJECT_SIZE         =
*      RFC_SERVER_REC             =
*      RFC_SERVER_DEST_REC        =
*      RFC_CLIENT_REC             =
*      RFC_CLIENT_DEST_REC        =
*      HTTP_SERVER_REC            =
*      HTTP_SERVER_DEST_REC       =
*      HTTP_CLIENT_REC            =
*      HTTP_CLIENT_DEST_REC       =
      EXCEPTIONS
        file_corrupt               = 1
        internal_error             = 2
        no_memory                  = 3
        parameter_missing          = 4
        invalid_parameter          = 5
        end_of_file                = 6
        open_error                 = 7
        seek_error                 = 8
        not_open                   = 9
        already_open               = 10
        OTHERS                     = 11
              .
    IF sy-subrc <> 0.
      CASE  sy-subrc.
        WHEN 1.
          MESSAGE i037(tc).
        WHEN 6.
          MESSAGE s038(tc).
        WHEN OTHERS.
*     ...
      ENDCASE.
      EXIT.
    ENDIF.

    IF block_head-rectype = '01'.
      block_head0 = block_head.
    ENDIF.

*   Output
    IF auth_rec-rectype = '65'.

      PERFORM p6_to_date_time_tz(rstr0400)
        USING auth_rec-timestamp1 lv_time lv_date.
      lv_millis = auth_rec-timestamp2 / 1000.
      CONCATENATE lv_time ',' lv_millis INTO lv_timestamp.

      ls_outtab-date       = lv_date.
      ls_outtab-timestamp  = lv_timestamp.
      ls_outtab-client     = block_head0-client.
      ls_outtab-username   = block_head0-username.
      ls_outtab-tcode      = block_head0-tcode.
      ls_outtab-abapprog   = auth_rec-abapprog.
      ls_outtab-abappos    = auth_rec-abappos.
      IF auth_rec-reslt    = 'A'.
        ls_outtab-rc       = 40.
      ELSE.
        ls_outtab-rc       = auth_rec-reslt * 4.
      ENDIF.
      ls_outtab-object     = auth_rec-object.
      SPLIT string1 AT '&' INTO
        ls_outtab-field1  ls_outtab-val1
        ls_outtab-field2  ls_outtab-val2
        ls_outtab-field3  ls_outtab-val3
        ls_outtab-field4  ls_outtab-val4
        ls_outtab-field5  ls_outtab-val5
        ls_outtab-field6  ls_outtab-val6
        ls_outtab-field7  ls_outtab-val7
        ls_outtab-field8  ls_outtab-val8
        ls_outtab-field9  ls_outtab-val9
        ls_outtab-field10 ls_outtab-val10
        .

*     Set color
      CLEAR: ls_color, ls_outtab-color[].
      ls_color-fieldname = 'RC'.
      IF ls_outtab-rc IS INITIAL.
        ls_color-color-col = 5. "COL_POSITIVE.
      ELSE.
        ls_color-color-col = 6. "COL_NEGATIVE.
      ENDIF.
      ls_color-color-int = 0.
      ls_color-color-inv = 0.
      APPEND ls_color TO ls_outtab-color.

*     Check selection
      IF    ls_outtab-username IN s_user
        AND ls_outtab-tcode    IN s_tcode
        AND ls_outtab-object   IN s_obj
        AND ls_outtab-rc       IN s_rc
        .
        APPEND ls_outtab TO lt_outtab.
      ENDIF.

    ENDIF.

  ENDDO.

* Close trace file
  CALL FUNCTION 'RSTR_CLOSE_FILE'
    EXCEPTIONS
      not_open = 1
      OTHERS   = 0.

  IF skip_dup = 'X'.
    SORT lt_outtab STABLE BY
          client
          username
          tcode
          abapprog
          abappos
          rc
          object
          field1
          val1
          field2
          val2
          field3
          val3
          field4
          val4
          field5
          val5
          field6
          val6
          field7
          val7
          field8
          val8
          field9
          val9
          field10
          val10
          .
    DELETE ADJACENT DUPLICATES FROM lt_outtab COMPARING
          client
          username
          tcode
          abapprog
          abappos
          rc
          object
          field1
          val1
          field2
          val2
          field3
          val3
          field4
          val4
          field5
          val5
          field6
          val6
          field7
          val7
          field8
          val8
          field9
          val9
          field10
          val10
          .
    SORT lt_outtab STABLE BY
          date
          timestamp.
  ENDIF.


*******************************************************************************
* Output
*******************************************************************************

  g_repid = sy-repid.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'DATE'.
  ls_fieldcat-outputlen = 10.
  ls_fieldcat-datatype  = 'DATS'.
  ls_fieldcat-seltext_s = 'DATE'.                           "#EC NOTEXT
  ls_fieldcat-seltext_m = 'DATE'.                           "#EC NOTEXT
  ls_fieldcat-seltext_l = 'DATE'.                           "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'TIMESTAMP'.
  ls_fieldcat-outputlen = 12.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'TIMESTAMP'.                      "#EC NOTEXT
  ls_fieldcat-seltext_m = 'TIMESTAMP'.                      "#EC NOTEXT
  ls_fieldcat-seltext_l = 'TIMESTAMP'.                      "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'CLIENT'.
  ls_fieldcat-rollname  = 'SYMANDT'.
  ls_fieldcat-outputlen = 3.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'CLIENT'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'CLIENT'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'CLIENT'.                         "#EC NOTEXT
  ls_fieldcat-no_out    = 'X'.
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'USERNAME'.
  ls_fieldcat-rollname  = 'XUBNAME'.
  ls_fieldcat-outputlen = 12.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'USERNAME'.                       "#EC NOTEXT
  ls_fieldcat-seltext_m = 'USERNAME'.                       "#EC NOTEXT
  ls_fieldcat-seltext_l = 'USERNAME'.                       "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'TCODE'.
  ls_fieldcat-rollname  = 'TCODE'.
  ls_fieldcat-outputlen = 20.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'TCODE'.                          "#EC NOTEXT
  ls_fieldcat-seltext_m = 'TCODE'.                          "#EC NOTEXT
  ls_fieldcat-seltext_l = 'TCODE'.                          "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'ABAPPROG'.
  ls_fieldcat-rollname  = 'PROGNAME'.
  ls_fieldcat-outputlen = 32.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'PROGRAM'.                        "#EC NOTEXT
  ls_fieldcat-seltext_m = 'PROGRAM'.                        "#EC NOTEXT
  ls_fieldcat-seltext_l = 'PROGRAM'.                        "#EC NOTEXT
*  ls_fieldcat-no_out    = 'X'.
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'ABAPPOS'.
  ls_fieldcat-outputlen = 6.
  ls_fieldcat-datatype  = 'INT4'.
  ls_fieldcat-seltext_s = 'LINE'.                           "#EC NOTEXT
  ls_fieldcat-seltext_m = 'LINE'.                           "#EC NOTEXT
  ls_fieldcat-seltext_l = 'LINE'.                           "#EC NOTEXT
  ls_fieldcat-no_out    = 'X'.
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'RC'.
  ls_fieldcat-outputlen = 3.
  ls_fieldcat-datatype  = 'INT4'.
  ls_fieldcat-emphasize = 'C300'. " 'X'.  "yellow
  ls_fieldcat-seltext_s = 'RESULT'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'RESULT'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'RESULT'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'OBJECT'.
  ls_fieldcat-rollname  = 'AGOBJECT'.
  ls_fieldcat-outputlen = 12.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'OBJECT'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'OBJECT'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'OBJECT'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'FIELD1'.
  ls_fieldcat-rollname  = 'AGRFIELD'.
  ls_fieldcat-outputlen = 10.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'FIELD1'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'FIELD1'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'FIELD1'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'VAL1'.
  ls_fieldcat-rollname  = 'AGVAL'.
  ls_fieldcat-outputlen = 40.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'VALUE1'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'VALUE1'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'VALUE1'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'FIELD2'.
  ls_fieldcat-rollname  = 'AGRFIELD'.
  ls_fieldcat-outputlen = 10.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'FIELD2'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'FIELD2'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'FIELD2'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'VAL2'.
  ls_fieldcat-rollname  = 'AGVAL'.
  ls_fieldcat-outputlen = 40.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'VALUE2'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'VALUE2'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'VALUE2'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'FIELD3'.
  ls_fieldcat-rollname  = 'AGRFIELD'.
  ls_fieldcat-outputlen = 10.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'FIELD3'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'FIELD3'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'FIELD3'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'VAL3'.
  ls_fieldcat-rollname  = 'AGVAL'.
  ls_fieldcat-outputlen = 40.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'VALUE3'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'VALUE3'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'VALUE3'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'FIELD4'.
  ls_fieldcat-rollname  = 'AGRFIELD'.
  ls_fieldcat-outputlen = 10.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'FIELD4'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'FIELD4'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'FIELD4'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'VAL4'.
  ls_fieldcat-rollname  = 'AGVAL'.
  ls_fieldcat-outputlen = 40.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'VALUE4'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'VALUE4'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'VALUE4'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'FIELD5'.
  ls_fieldcat-rollname  = 'AGRFIELD'.
  ls_fieldcat-outputlen = 10.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'FIELD5'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'FIELD5'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'FIELD5'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'VAL5'.
  ls_fieldcat-rollname  = 'AGVAL'.
  ls_fieldcat-outputlen = 40.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'VALUE5'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'VALUE5'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'VALUE5'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'FIELD6'.
  ls_fieldcat-rollname  = 'AGRFIELD'.
  ls_fieldcat-outputlen = 10.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'FIELD6'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'FIELD6'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'FIELD6'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'VAL6'.
  ls_fieldcat-rollname  = 'AGVAL'.
  ls_fieldcat-outputlen = 40.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'VALUE6'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'VALUE6'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'VALUE6'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'FIELD7'.
  ls_fieldcat-rollname  = 'AGRFIELD'.
  ls_fieldcat-outputlen = 10.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'FIELD7'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'FIELD7'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'FIELD7'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'VAL7'.
  ls_fieldcat-rollname  = 'AGVAL'.
  ls_fieldcat-outputlen = 40.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'VALUE7'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'VALUE7'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'VALUE7'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'FIELD8'.
  ls_fieldcat-rollname  = 'AGRFIELD'.
  ls_fieldcat-outputlen = 10.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'FIELD8'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'FIELD8'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'FIELD8'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'VAL8'.
  ls_fieldcat-rollname  = 'AGVAL'.
  ls_fieldcat-outputlen = 40.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'VALUE8'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'VALUE8'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'VALUE8'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'FIELD9'.
  ls_fieldcat-rollname  = 'AGRFIELD'.
  ls_fieldcat-outputlen = 10.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'FIELD9'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'FIELD9'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'FIELD9'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'VAL9'.
  ls_fieldcat-rollname  = 'AGVAL'.
  ls_fieldcat-outputlen = 40.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'VALUE9'.                         "#EC NOTEXT
  ls_fieldcat-seltext_m = 'VALUE9'.                         "#EC NOTEXT
  ls_fieldcat-seltext_l = 'VALUE9'.                         "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'FIELD10'.
  ls_fieldcat-rollname  = 'AGRFIELD'.
  ls_fieldcat-outputlen = 10.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'FIELD10'.                        "#EC NOTEXT
  ls_fieldcat-seltext_m = 'FIELD10'.                        "#EC NOTEXT
  ls_fieldcat-seltext_l = 'FIELD10'.                        "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname = 'VAL10'.
  ls_fieldcat-rollname  = 'AGVAL'.
  ls_fieldcat-outputlen = 40.
  ls_fieldcat-datatype  = 'CHAR'.
  ls_fieldcat-seltext_s = 'VALUE10'.                        "#EC NOTEXT
  ls_fieldcat-seltext_m = 'VALUE10'.                        "#EC NOTEXT
  ls_fieldcat-seltext_l = 'VALUE10'.                        "#EC NOTEXT
  APPEND ls_fieldcat TO lt_fieldcat.

  ls_layout-colwidth_optimize = 'X'.
*  ls_layout-zebra             = 'X'.
  ls_layout-coltab_fieldname  = 'COLOR'.
*  ls_layout-window_titlebar   = 'Authorization trace'(011).

  CLEAR ls_event.
  ls_event-name = slis_ev_user_command.
  ls_event-form = 'SHOW_ABAP'.
  APPEND ls_event TO lt_events.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = g_repid
      i_callback_top_of_page   = 'TOP_PG'
*     i_callback_pf_status_set = 'HANDLE_EVENT_PF_STATUS'
*     i_callback_user_command  = 'HANDLE_EVENT_USER_COMMAND'
*     i_grid_title             = 'Authorization trace'(011)
      is_layout                = ls_layout
      it_fieldcat              = lt_fieldcat
      it_events                = lt_events
*     is_print                 = ls_prnt
    TABLES
      t_outtab                 = lt_outtab
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

*&---------------------------------------------------------------------*
*&      Form  TOP_PG
*&---------------------------------------------------------------------*
FORM top_pg .

  DATA : t_header        TYPE slis_t_listheader.
  DATA : s_header        TYPE slis_listheader.
  DATA : inf             TYPE slis_listheader-info.
  DATA : list_lines      TYPE i,
         ld_linesc(10)   TYPE c.

  DESCRIBE TABLE lt_outtab LINES list_lines.
  ld_linesc = list_lines.

  CLEAR: s_header.
  s_header-typ   =  'H'.
  s_header-info  =  'Authorization trace'(011).
  APPEND s_header TO t_header.

  CLEAR: s_header.
  s_header-typ  = 'S'.
  CONCATENATE 'System'(013) ':' INTO s_header-key.
  CONCATENATE sy-sysid 'on' sy-host 'client' sy-mandt
    INTO s_header-info SEPARATED BY space.
  IF username IS NOT INITIAL.
    CONCATENATE s_header-info 'for user'(023) username
      INTO s_header-info SEPARATED BY space.
  ENDIF.
  APPEND s_header TO t_header.

  CLEAR: s_header.
  s_header-typ  = 'S'.
  CONCATENATE 'Selection'(014) ':' INTO s_header-key.
  WRITE datefrom TO s_header-info+0(10) DD/MM/YYYY.
  WRITE timefrom TO s_header-info+12(8) USING EDIT MASK '__:__:__'.
  WRITE '-'      TO s_header-info+21(1).
  WRITE dateto   TO s_header-info+23(10) DD/MM/YYYY.
  WRITE timeto   TO s_header-info+35(8) USING EDIT MASK '__:__:__'.
  APPEND s_header TO t_header.

  IF max_rec_reached = 'X'.
    CLEAR: s_header.
    s_header-typ   =  'A'.
    s_header-info  = 'maximum count of trace records reached'(016).
    APPEND s_header TO t_header.
  ENDIF.

  CLEAR: s_header.
  s_header-typ   =  'A'.
  CONCATENATE ld_linesc 'records seleced for display'(012)
    INTO s_header-info SEPARATED BY space.
  APPEND s_header TO t_header.

  IF skip_dup = 'X'.
    CLEAR: s_header.
    s_header-typ   =  'A'.
    s_header-info  = 'Duplicate records are suppressed'(017).
    APPEND s_header TO t_header.
  ENDIF.

  CLEAR: s_header.
  s_header-typ   =  'A'.
  s_header-info  =
    'Use double-click to navigate to the authority check'(015).
  APPEND s_header TO t_header.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = t_header
*     i_logo             = ''
    .

ENDFORM.                    " TOP_PG

*&---------------------------------------------------------------------*
*&      Form  SHOW_ABAP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->R_UCOMM      text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
FORM show_abap USING r_ucomm LIKE sy-ucomm
                     rs_selfield TYPE slis_selfield.

* see RSTRAC22 form SHOW_ABAP

*  DATA: program(40),
*        line TYPE i.
  DATA: cont TYPE TABLE OF rcont WITH HEADER LINE.

  CHECK r_ucomm = '&IC1' AND rs_selfield-tabindex > 0.
  READ TABLE lt_outtab INTO ls_outtab INDEX rs_selfield-tabindex.
  CHECK sy-subrc = 0 AND ls_outtab-abapprog IS NOT INITIAL AND ls_outtab-abappos IS NOT INITIAL.

  LOAD REPORT ls_outtab-abapprog PART 'CONT' INTO cont.
  READ TABLE cont WITH KEY offset = ls_outtab-abappos.
  FREE cont[].

  CALL FUNCTION 'EDITOR_PROGRAM'
    EXPORTING
      display     = 'X'
      line        = cont-line
      program     = cont-source
    EXCEPTIONS
      application = 1
      OTHERS      = 2.
  IF sy-subrc <> 0.
    MESSAGE i036(tc).
  ENDIF.

ENDFORM.                    "SHOW_ABAP

1 Comment

  1. Dear Frank,

    probably there is a small bug in the trace analysis, for example table class &NC& is not displayed correctly within S_TABU_DIS:

    & seems to be interpreted as "next coloumn" because NC is displayed in coloumn FIELD4 (correct is VALUE3)

    DATE TIMESTAMP USERNAME TCODE PROGRAM RESULT OBJECT FIELD1 VALUE1 FIELD2 VALUE2 FIELD3 VALUE3 FIELD4 VALUE4
    24.01.2011 17:21:46,719 BAUERCTI SE16 SAPLSVIX 0 S_TABU_DIS tcode SE16 ACTVT 03 DICBERCLS  NC 

    Thank you for improving that great report - we don't have SAPKB70021 or SAPKB70107 yet!

    Christian Bauer

    Schaeffler Technologies GmbH & Co. KG