Finding the Enhancements of a SAP transaction code

Use the following code to find the User-Exits of an SAP transaction code


*&---------------------------------------------------------------------*
*& Report  Z_FIND_ENHANCEMENTS
*&
*&---------------------------------------------------------------------*
*& Created By: Pedro Vidigal
*&
*&---------------------------------------------------------------------*
report  z_find_enhancements.

*----------------------------------------------------------------------*
*       CLASS lcl_main DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_main definition.

  public section.
    data: lt_tadir    type table of tadir.
    methods: execute importing value(im_tcode) type tstc-tcode
                               value(im_pgmna) type tstc-pgmna,
             go_to_transaction.

  protected section.
  private section.
    methods: retrieve_enhancements importing value(im_tcode) type tstc-tcode
                                             value(im_pgmna) type tstc-pgmna.
endclass.                    "lcl_main DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_main IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_main implementation.
  method execute.

    me->retrieve_enhancements( im_tcode = im_tcode
                               im_pgmna = im_pgmna ).

  endmethod.                    "execute

  method retrieve_enhancements.
    data: ls_tadir    type  tadir,
          ls_tstc     type  tstc,
          ls_tfdir    type  tfdir,
          ls_enlfdir  type  enlfdir.


    if im_tcode is not initial.
      " Retrieve the Transaction information
      select single * from tstc into ls_tstc
      where tcode eq im_tcode.
    elseif im_pgmna is not initial.
      ls_tstc-pgmna = im_pgmna.
    endif.

    if ls_tstc-pgmna is not initial.
      "
      select single * from tadir into ls_tadir
      where pgmid     = 'R3TR'
        and object    = 'PROG'
        and obj_name  = ls_tstc-pgmna.
      if sy-subrc ne 0.
        " We will check if it is a Module POOL program

        " Function Module   information
        select single * from tfdir into ls_tfdir where pname = ls_tstc-pgmna.
        " Additional information of function module
        select single * from enlfdir into ls_enlfdir
        where funcname = ls_tfdir-funcname.

        select single * from tadir into ls_tadir
        where pgmid   = 'R3TR'
        and object    = 'FUGR'
        and obj_name  = ls_enlfdir-area.

      endif.
    endif.

    " Retrieve the Enhancements
    select * from tadir into table me->lt_tadir
      where pgmid     = 'R3TR'
        and object    in ('SMOD' ,  " User-Exits
                          'SXSD')   " BADIS
        and devclass  = ls_tadir-devclass.

  endmethod.                    "retrieve_enhancements

  method go_to_transaction.
    data: lv_cursor   type char30,
          lv_object   type tadir-object,
          ls_tadir    type tadir.
    clear: lv_object, ls_tadir.

    get cursor field lv_cursor.
    check lv_cursor(8) eq 'LS_TADIR'.

    read table me->lt_tadir into ls_tadir with key obj_name = sy-lisel+1(20).
    check ls_tadir is not initial.

    move ls_tadir-object to lv_object.
    case lv_object.
      when 'SMOD'.
        set parameter id 'MON' field sy-lisel+1(10).
        call transaction 'SMOD' and skip first screen.
      when 'SXSD'.
        set parameter id 'EXN' field sy-lisel+1(20).
        call transaction 'SE18' and skip first screen.
    endcase.

  endmethod.                    "go_to_transaction
endclass.                    "lcl_main IMPLEMENTATION


parameters : p_tcode like tstc-tcode, " Transaction Code
             p_pgmna like tstc-pgmna. " Program Name

start-of-selection.

  data: lo_main type ref to lcl_main.
  create object lo_main.

  lo_main->execute( im_tcode = p_tcode
                    im_pgmna = p_pgmna ).


**********************************************************************
* Display Enhancements
**********************************************************************
  data: ls_tstct    type tstct,
        ls_modsapt  type modsapt.
  data: lv_txt(60) type c,
        lv_smod type i ,
        lv_badi type i ,
        lv_object2(30) type c.
  clear : lv_smod, lv_badi , lv_object2.


  data: ls_tadir type tadir.

  select single * from tstct into ls_tstct
    where sprsl eq sy-langu
    and tcode eq p_tcode.


  " Header
  format color col_positive intensified off.
  write:/(19) 'Transaction Code - ',
  20(20) p_tcode,          " Transaction Code
  45(50) ls_tstct-ttext.    " Transaction description
  skip.

  if ls_tstct is not initial.
    if not lo_main->lt_tadir[] is initial.

      " Enhancement info table header
      format color col_heading intensified on.
      write:/1 sy-vline,
      2 'Enhancement/ Business Add-in',
      41 sy-vline ,
      42 'Description',
      105 sy-vline.
      write:/(105) sy-uline.

      loop at lo_main->lt_tadir into ls_tadir.

        clear lv_txt.

        at new object.
          if ls_tadir-object = 'SMOD'.
            lv_object2 = 'Enhancement' .
          elseif ls_tadir-object = 'SXSD'.
            lv_object2 = ' Business Add-in'.
          endif.
          format color col_group intensified on.
          write:/1    sy-vline,
                 2    lv_object2,
                 105  sy-vline.
        endat.

        case ls_tadir-object.
          when 'SMOD'.
            " Enhanements
            lv_smod = lv_smod + 1.
            select single modtext into lv_txt
              from modsapt
              where sprsl = sy-langu
                and name = ls_tadir-obj_name.
            format color col_normal intensified off.
          when 'SXSD'.
            " For BADis
            lv_badi = lv_badi + 1 .
            select single text into lv_txt
              from sxs_attrt
              where sprsl = sy-langu
              and exit_name = ls_tadir-obj_name.
            format color col_normal intensified on.
        endcase.
        write:/1    sy-vline,
               2    ls_tadir-obj_name hotspot on,
               41   sy-vline ,
               42   lv_txt,
               105  sy-vline.

        at end of object.
          write : /(105) sy-uline.
        endat.
      endloop.

      write:/(105) sy-uline.
      skip.
      format color col_total intensified on.
      write:/ 'No.of Exits:' , lv_smod.
      write:/ 'No.of BADis:' , lv_badi.

    else.
      format color col_negative intensified on.
      write:/(105) 'No userexits or BADis exist'.
    endif.
  else.
    format color col_negative intensified on.
    write:/(95) 'Transaction Code Does Not Exist'.
  endif.


" Go to the corresponding Transaction
at line-selection.
  lo_main->go_to_transaction( ).

No comments:

Post a Comment