* Version 0009                                      Date: 15-Nov-2004
report ztcode_list message-id z2 no standard page heading line-size 170.

tables:
  tadir
, tstc
, tstct
.
constants:
  c_fld      like dd03l-fieldname value 'OBJ_NAME' "Default sort. field
, our_devcl  like tadir-devclass  value 'ZGSM'     "Our Dev. Class
.
data:
  st_cnt(10)
, head_ln    like sy-staro        value  3         "Header rows
, last_ln    like sy-staro                         "Last line in list
, fld        like dd03l-fieldname value  c_fld     "Initial sort. field
, sav_fld    like dd03l-fieldname value  c_fld     "Saved state of
                                                   " sorting conditions
, sort_flg                        value 'X'        " 'X' - ascending
, v_obj_name like e071-obj_name
, pop_txt    like spop-textline2
, ans
, cl_devcl   type i
, cl_pgmna   type i
, q_pgmna(40)
, cant_switch_lang                  "Cannot switch language
, inst_lang(8)                      "Installed languages string
, lang_len   type i
, lang_pos   like sy-fdpos
, ok_code    like sy-ucomm
, ln         like sy-dbcnt
, st_ln(16)  type c
, i          type i               value 0
, new_idx    like sy-lilli        value 0
, sav_idx    like sy-lilli        value 0
, sav_eronly

, begin of it occurs 1000.
    include structure tadir.
data:
    pgmna like tstc-pgmna
,   ttext like tstct-ttext
,   errpg
, end   of it
.
selection-screen skip.

select-options:
  so_tcode for tstc-tcode      default 'Z*' option cp sign i
.
selection-screen skip.

selection-screen begin of block b1
                          with frame
                          title text-017
                          .
  select-options:
    so_cname for tadir-author    "efault  sy-uname
  .
  selection-screen begin of line.
    selection-screen pushbutton 33(9) b_cname user-command cnam.
    selection-screen pushbutton 43(4) b_nonam user-command nona.
  selection-screen end   of line.

  selection-screen skip.
  select-options:
    so_devcl for tadir-devclass  "efault 'Z*'
  .
  selection-screen begin of line.
    selection-screen pushbutton 33(6) b_devc1 user-command dev1.
    selection-screen pushbutton 40(8) b_devc2 user-command dev2.
    selection-screen pushbutton 49(4) b_nodev user-command node.
  selection-screen end   of line.

  selection-screen skip.
  parameters:
*---Maximum number of hits (unlimited = 0)
    p_rows  like rseumod-tbmaxsel default  1000
  .
  selection-screen skip.
  selection-screen uline.

  selection-screen begin of line.
    selection-screen position 1.
    parameter p_count(12) modif id out.
    selection-screen pushbutton 16(13) b_count user-command coun.
    selection-screen comment    32(50) c_count.
  selection-screen end   of line.
selection-screen end   of block b1.

selection-screen skip.

selection-screen begin of block b2
                          with frame
                          title text-018
                          .
  parameter
*---Language key
    p_langu like tstct-sprsl      default  sy-langu
  .
  selection-screen begin of line.
    selection-screen pushbutton 33(18) b_langu user-command lang.
  selection-screen end   of line.

  parameters:
*---Zebra-style output
    p_zebra  as checkbox        default ' '
*---Start transaction in new mode
  , p_newmod as checkbox        default ' '
*---Ask before call transaction
  , p_ask    as checkbox        default 'X'
*---Check program existence
  , p_check  as checkbox        default 'X' user-command chck
*---Only display TCODEs with non-existing program
  , p_eronly as checkbox        default ' '
  .
selection-screen end   of block b2.

include <list>.
*-----------------------------------------------------------------------
define get_param.
  call 'C_SAPGPARAM'
    id 'NAME'  field &1
    id 'VALUE' field &2
    .
end-of-definition. "GET_PARAM
*-----------------------------------------------------------------------
define confirm_step.
  clear ans.
  call function 'POPUP_TO_CONFIRM_STEP'
       exporting defaultoption  = 'N'
                 textline1      = &1
                 textline2      = &2
                 titel          = &3
                 start_column   = 25
                 start_row      =  5
*                cancel_display =  space
       importing answer         =  ans
                 .
end-of-definition. "CONFIRM_STEP
*-----------------------------------------------------------------------
define call_tcode.
  move &1 to pop_txt. condense pop_txt.
  concatenate pop_txt &2 into pop_txt separated by ' - '.
  confirm_step 'Do you want to launch transaction'(008)
                pop_txt
               'Launch transaction'(009)
                .
  case ans.
    when 'J'.    perform call_transaction using &1.
    when others. perform action_cancelled.
  endcase.
end-of-definition. "CALL_TCODE
*-----------------------------------------------------------------------
define navigate.
  move &2 to v_obj_name.
  perform navigate_to_object using &1 v_obj_name.
end-of-definition. "NAVIGATE
*-----------------------------------------------------------------------
define setup_colors.
  case it-devclass.
    when '$TMP'.                         "Local objects
      cl_devcl = col_negative.
    when  our_devcl.                     "Our devclass
      cl_devcl = col_positive.
    when others.
      if     it-devclass(1) = 'Z' or     "Other Z-devclass
             it-devclass(1) = 'Y'.       "   or Y-devclass
        cl_devcl = col_heading.
      elseif it-devclass(2) = 'J3'.      "3rd party devclass
        cl_devcl = col_total.
      else.
        cl_devcl = col_normal.
      endif.
  endcase.
  if it-errpg = 'X' and p_check = 'X'.
    cl_pgmna = col_negative. q_pgmna  = 'Program does not exist'(019).
  else.
    cl_pgmna = col_total.    clear q_pgmna.
  endif.
  if p_zebra = 'X'.
    i = ( i + 1 ) mod 2.
    format intensified = i.
  endif.
end-of-definition. "SETUP_COLORS
*-----------------------------------------------------------------------
define select_valid_line.
*'Place cursor on a valid line'
* message s898(s1). "<- Message hasn't translation in Russian
*'Select a valid line'
  message s015(sr).
  exit.
end-of-definition. "SELECT_VALID_LINE
*-----------------------------------------------------------------------
define select_valid_field.
*-Restore default sorting
  fld = c_fld.
*'Position the cursor on a table field'
  message w303(td).
* exit.
end-of-definition. "SELECT_VALID_FIELD
*-----------------------------------------------------------------------
define init_so_cname.
  refresh so_cname.
  so_cname-low    = &1.
  so_cname-sign   = 'I'.
  so_cname-option = 'EQ'.
  append so_cname.
end-of-definition. "INIT_SO_CNAME
*-----------------------------------------------------------------------
define init_so_devcl.
  refresh so_devcl.
  so_devcl-low    = &1.
  so_devcl-sign   = 'I'.
  so_devcl-option = &2.
  append so_devcl.
end-of-definition. "INIT_SO_DEVCL
*-----------------------------------------------------------------------
initialization.
  perform init.

*-----------------------------------------------------------------------
at selection-screen.
  perform at_selection_screen.

*-----------------------------------------------------------------------
at selection-screen output.
  perform at_selection_screen_output.

*-----------------------------------------------------------------------
top-of-page.
  perform top_of_page.

*-----------------------------------------------------------------------
top-of-page during line-selection.
  perform top_of_page.

*-----------------------------------------------------------------------
start-of-selection.
  perform refresh_list.
* perform get_data.

*-----------------------------------------------------------------------
end-of-selection.
* perform write_list.

*-----------------------------------------------------------------------
at line-selection.                    "When user clicked on a line
  perform at_line_selection.          "Only works if GUI-status not set

*-----------------------------------------------------------------------
at user-command.
  perform at_user_command.

*-----------------------------------------------------------------------
*nclude ztop_users.
form init.
* case sy-uname.
*   when 'SAP*'
*     or  bc_adm1
*     or  bc_adm2
*     or  bc_dev1
*     or  bc_dev2
*         .
*   when others. leave program.
* endcase.

*-Get installed languages
  move sy-langu to p_langu.         "Set logon language as initial
  clear cant_switch_lang.

  get_param 'zcsa/installed_languages' inst_lang.

  lang_len = strlen( inst_lang ).   "Length of a languages-string

  if lang_len = 0.
    cant_switch_lang = 'X'.
  else.
    search inst_lang for sy-langu.  "Get position of logon language
    if sy-subrc = 0.
      lang_pos = sy-fdpos.          "at installed languages string
    else.
      cant_switch_lang = 'X'.
    endif.
  endif.

  move:
    '@0M@Count'(010)                                 to b_count
  , 'Count entries matching selection criteria'(011) to c_count
  , '@M1@I am'(012)                                  to b_cname
*     BM D6 LC M1
  , '@11@'                                           to b_nonam
  , '@4F@Next language'(013)                         to b_langu
  , '@5B@Z*'                                         to b_devc1
  , '@5C@$TMP'                                       to b_devc2
  , '@11@'                                           to b_nodev
  ,  p_eronly                                        to sav_eronly
  .
endform. "INIT
*-----------------------------------------------------------------------
form at_selection_screen_output.
  loop at screen.
    if screen-group1 = 'OUT'.
      screen-input = '0'.
      modify screen.
    elseif screen-name = 'P_ERONLY'.
      if p_check = 'X'.
        screen-input = '1'.
      else.
        screen-input = '0'.
        clear p_eronly.
      endif.
      modify screen.
    endif.
  endloop.
endform. "AT_SELECTION_SCREEN_OUTPUT
*-----------------------------------------------------------------------
form at_selection_screen.
* if ok_code is initial.
    move sy-ucomm to ok_code.
    case ok_code.
      when 'COUN'.  perform count_entries.
      when 'LANG'.  perform next_language.
      when 'CNAM'.  init_so_cname sy-uname.
      when 'NONA'.  refresh so_cname.
      when 'DEV1'.  init_so_devcl 'Z*'   'CP'.
      when 'DEV2'.  init_so_devcl '$TMP' 'EQ'.
      when 'NODE'.  refresh so_devcl.
      when 'CHCK'.  if p_check = 'X'. p_eronly = sav_eronly.
                                else. sav_eronly = p_eronly. endif.
*     when 'ONLI'.  " just continue
*     when  others. if ok_code(1) ne '/'.
*                     perform call_transaction using ok_code.
*                   endif.
    endcase.
* else.
*   clear ok_code. "prevent double-launch
* endif.
endform. "AT_SELECTION_SCREEN
*-----------------------------------------------------------------------
form at_user_command.
  case sy-pfkey.
    when 'MAIN'.
      case sy-ucomm.
        when 'SELE'. perform at_line_selection.
        when 'REFR'. perform refresh_list.
        when 'SRTA'. sort_flg = 'X'. perform sort_list.
        when 'SRTD'. sort_flg = ' '. perform sort_list.
        when 'SSCR'. perform call_selection_screen.
        when 'LANG'. perform next_language.
                     perform refresh_list.
        when 'BACK'
          or 'EXIT'
          or 'CANCEL'
              .      set screen 0. leave screen.
      endcase.
    when others.     if ok_code(1) ne '/'.
                       perform call_transaction using sy-ucomm.
                     endif.
  endcase.
endform. "AT_USER_COMMAND
*-----------------------------------------------------------------------
form top_of_page.
  format color col_heading intensified on.
  uline.
  write:
  /         sy-vline                                       no-gap
  , icon_execute_object as icon "otspot
      quickinfo 'Execute'(001)
  , icon_layout_control as icon "otspot
      quickinfo 'View definition'(002)
  , at   8 'Transaction code________________________'(003) no-gap
  , at  48  sy-vline                                       no-gap
  .
  set left scroll-boundary.
  write:
    at  49 'Description_________________________'(004)     no-gap
  , at  85  sy-vline                                       no-gap
  , at  86 'Author______'(006)                             no-gap
  , at  98  sy-vline                                       no-gap
  , at  99 'Program_________________________________'(005) no-gap
  , at 139  sy-vline                                       no-gap
  , at 140 'Development Class_____________'(007)           no-gap
  , at 170  sy-vline                                       no-gap
  .
  uline.
endform. "TOP_OF_PAGE
*-----------------------------------------------------------------------
form at_line_selection.
  if sy-curow gt head_ln and        "If relative line > HEAD_LN and
     sy-lilli le last_ln.           "  absolute line inside of list
    get cursor field fld.
    perform highlight.

    case fld.
      when 'ICON_EXECUTE_OBJECT'
        or 'IT-OBJ_NAME'.         if it-errpg = 'X' and p_check = 'X'.
*----------------------------------'Program & does not exist'
                                    message s017(ds) with it-pgmna.
*----------------------------------'& & not found'
*                                   message e524(ed)
*                                      with 'Program' it-pgmna.
                                  else.
                                    call_tcode it-obj_name it-ttext.
                                  endif.
      when 'ICON_LAYOUT_CONTROL'
        or 'IT-TTEXT'.            navigate 'TRAN' it-obj_name.
      when 'IT-AUTHOR'.           perform show_user_details
                                    using it-author sy-mandt.
      when 'IT-PGMNA'.            navigate 'PROG' it-pgmna.
      when 'IT-DEVCLASS'.         navigate 'DEVC' it-devclass.
      when others.
*--------------------'Navigation through this column not possible'
                                  message s065.
    endcase.
  else. select_valid_line. endif.
endform. "AT_LINE_SELECTION
*-----------------------------------------------------------------------
form back_if_detail.           "REUSES EXISTING OUTPUT
*-If detail list level > 0 then decrease it
  if sy-lsind > 0. subtract 1 from sy-lsind. endif.
endform. "BACK_IF_DETAIL
*-----------------------------------------------------------------------
form list_return using list_idx like sy-lsind.
*-return list to previous position
  scroll list index list_idx to column sy-staco.
  scroll list index list_idx to page   sy-cpage line sy-staro.
endform. "LIST_RETURN
*-----------------------------------------------------------------------
form action_cancelled.
*-'Action cancelled by user'
  message s024(es).
endform. "ACTION_CANCELLED
*-----------------------------------------------------------------------
form highlight.
  check p_zebra is initial.

*-Switch ON new mark
  modify current line line format intensified.
  new_idx = sy-lilli.

  if not sav_idx is initial and new_idx <> sav_idx.
*---Switch OFF old mark
    read line sav_idx.
    modify current line line format intensified off.

*---Return to new line
    read line new_idx.
  endif.
*-Save state
  move sy-lilli to sav_idx.
endform. "HIGHLIGHT
*-----------------------------------------------------------------------
form count_entries.
* call function 'SAPGUI_PROGRESS_INDICATOR'
*      exporting text = 'Calculating...'(000).

  clear ln.
  select count( * )
         into ln
         from ( (           tadir as a
                  join tstc  as c
           on obj_name = c~tcode )
           left join tstct as t
           on sprsl = p_langu
           and t~tcode = c~tcode )
           where pgmid  = 'R3TR'
             and object = 'TRAN'
             and obj_name in so_tcode
             and author   in so_cname
             and devclass in so_devcl
                 .
  move ln to st_ln. condense st_ln. p_count = st_ln.
endform. "COUNT_ENTRIES
*-----------------------------------------------------------------------
form get_data.
* clear sav_idx.
  refresh it. clear it.
  select a~obj_name
         a~author
         a~devclass
         c~pgmna
         t~ttext
         into corresponding fields of table it
         up to p_rows rows
         from ( (           tadir as a
                  join tstc  as c
           on obj_name = c~tcode )
           left join tstct as t
           on sprsl = p_langu
           and t~tcode = c~tcode )
           where pgmid  = 'R3TR'
             and object = 'TRAN'
             and obj_name in so_tcode
             and author   in so_cname
             and devclass in so_devcl
                 .
  if p_check = 'X'.
    loop at it where pgmna ne space.
      select count(*) from trdir where name = it-pgmna.
      if sy-subrc <> 0. it-errpg = 'X'. modify it. endif.
    endloop.
    if p_eronly = 'X'. delete it where errpg = space. endif.
  endif.
  describe table it lines sy-tfill.
  move sy-tfill to st_cnt. condense st_cnt.
endform. "GET_DATA
*-----------------------------------------------------------------------
form refresh_list.
  perform get_data.
  set titlebar '001' with st_cnt.
  set pf-status 'MAIN'.
  perform sort_it using sav_fld changing sav_fld.
  perform write_list.
endform. "REFRESH_LIST
*-----------------------------------------------------------------------
form write_list.
  perform back_if_detail.
  format color col_key intensified off.
  loop at it.
    setup_colors.
    write:
    / sy-vline    no-gap
    , icon_execute_object as icon hotspot color col_key
*       quickinfo 'Execute'(001)
    , icon_layout_control as icon hotspot color col_key
*       quickinfo 'View definition'(002)
    , it-obj_name no-gap color col_key
    , sy-vline    no-gap
    .
    set left scroll-boundary.
    write:
      it-ttext    no-gap color col_key
    , sy-vline    no-gap
    , it-author   no-gap color col_normal
    , sy-vline    no-gap
    , it-pgmna    no-gap color = cl_pgmna
                         quickinfo q_pgmna
    , sy-vline    no-gap
    , it-devclass no-gap color = cl_devcl
    , sy-vline    no-gap
    .
    hide:
      it-obj_name
    , it-ttext
    , it-pgmna
    , it-author
    , it-devclass
    , it-errpg
    .
  endloop.
  move sy-linno to last_ln.    "Remember number of last line in list
  uline.
  if it[] is initial.
*--'No table entries found for specified key'
    message s429(mo).
  else.
    perform put_sort_indicator.
    perform list_return using 1.   "Return to previous position
  endif.
endform. "WRITE_LIST
*-----------------------------------------------------------------------
form sort_list.
  perform get_cursor_field.
* if fld is initial. exit. endif.
  perform sort_it using fld changing sav_fld.
  perform write_list.
endform. "SORT_LIST
*-----------------------------------------------------------------------
form get_cursor_field.
  if sy-curow gt head_ln and        "If relative line > HEAD_LN and
     sy-lilli le last_ln.           "  absolute line inside of list
    get cursor field fld.
*---for prevent dump when SY-VLINE selected
    if fld = 'SY-VLINE'. clear fld. exit. endif.
*---get field name of internal table
    split fld at '-' into fld fld.
  else. clear fld. endif.
endform. "GET_CURSOR_FIELD
*-----------------------------------------------------------------------
form sort_it using value(fld)
          changing sav_fld like dd03l-fieldname
                   .
  if fld is initial. select_valid_field.
               else. move fld to sav_fld. endif.
  if sort_flg = 'X'.
    sort it stable by (fld)  ascending.  " STABLE sorting!
  else.
    sort it stable by (fld) descending.  " STABLE sorting!
  endif.
endform. "SORT_IT
*-----------------------------------------------------------------------
data ps_sortind type i.

form put_ind using value(flag) value(linno) value(cl_ind).
  data sm_sortind like sym_up_triangle.

  if ps_sortind > 0.
    if flag = 'X'. sm_sortind = sym_up_triangle.
             else. sm_sortind = sym_down_triangle. endif.

    skip to line linno.
    write at ps_sortind sm_sortind as symbol color = cl_ind inverse.
  endif.
endform. "PUT_IND
*-----------------------------------------------------------------------
form put_sort_indicator.
  case sav_fld.
    when 'OBJ_NAME'. ps_sortind =   8.
    when 'TTEXT'.    ps_sortind =  49.
    when 'AUTHOR'.   ps_sortind =  86.
    when 'PGMNA'.    ps_sortind =  99.
    when 'DEVCLASS'. ps_sortind = 140.
    when others.     clear ps_sortind.
  endcase.

  perform put_ind using sort_flg 3 col_heading.
endform. "PUT_SORT_INDICATOR
*-----------------------------------------------------------------------
form show_user_details using v_bname like usr02-bname
                             v_mandt like usr02-mandt
                             .
  call function 'SUSR_SHOW_USER_DETAILS'
       exporting
         bname = v_bname
         mandt = v_mandt
         .
endform. "SHOW_USER_DETAILS
*-----------------------------------------------------------------------
form navigate_to_object using value(object)   like e071-object
                              value(obj_name) like e071-obj_name
                              .
  call function 'TR_OBJECT_JUMP_TO_TOOL'
       exporting
         iv_pgmid          = 'R3TR'
         iv_object         =  object
         iv_obj_name       =  obj_name
         iv_action         = 'SHOW'
       exceptions
         jump_not_possible =  1
         .
  if sy-subrc <> 0.
    if sy-msgid = 'EU' and sy-msgno = 297.
      perform navigate_to_menu using obj_name.
    else.
      message id sy-msgid type 'I' number sy-msgno
         with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.
  endif.
endform. "NAVIGATE_TO_OBJECT
*-----------------------------------------------------------------------
include zbdcincl.

form navigate_to_menu using value(v_menu).
  dyn 'SAPLBMEN'     '0200'.
  fld 'BDC_CURSOR'   'BMENUNAME-ID'.
  fld 'BDC_OKCODE'   '=SHOW'.
  fld 'BMENUNAME-ID'  v_menu.

* dyn 'SAPMSSY0'     '0120'.
* fld 'BDC_OKCODE'   '=TRRT'.

  tra 'SE43'.
endform. "NAVIGATE_TO_MENU
*-----------------------------------------------------------------------
form call_transaction using value(v_tcode). "like sy-tcode.
  data:
    mode    like sy-tabix                 "#EC NEEDED
  , t_tcode like sy-tcode

*---See include LSEUKTOP for more info on transaction types
  , hex_men type x value '01'
  .
  select single * from tstc where tcode = v_tcode.

  if sy-subrc <> 0.
*--'Transaction & is unknown'
*   message e031(00) with tcode.
*--'Transaction & does not exist'
    message e343(s#) with v_tcode.
*   exit.
  elseif tstc-cinfo o hex_men.
*-Equivalent check:
* elseif tstc-pgmna(4) = 'MENU'.
*--'&1 is an area menu. You can no longer edit area menus here.'
    message e297(eu) with v_tcode.
*   exit.
  endif.

  authority-check object 'S_TCODE'
    id 'TCD' field v_tcode
    .
  if sy-subrc <> 0.
*--'You are not authorized to use transaction &'
*   message s661(bt) with tcode.
*--'You have no authorization for Transaction &'
    message s261(sf) with v_tcode.
  else.
    if p_newmod = 'X'.
*-----Some redundance for compatibility to avoid dumps :)
      t_tcode = v_tcode.
      call function 'TH_CREATE_MODE'
           exporting transaktion = t_tcode
           importing mode        = mode
           exceptions
             max_sessions        = 1
             internal_error      = 2
             no_authority        = 3
             others              = 4
             .
      if sy-subrc <> 0.
*------'Unable to create a new window'
        message s064(seu_manager).
      else.
*------'Starting tool...'
        message s063(seu_manager).
      endif.
    else.
      call transaction v_tcode.
    endif.
  endif.
endform. "CALL_TRANSACTION
*-----------------------------------------------------------------------
form call_selection_screen.
*-Show selection screen
  call selection-screen 1000 starting at 20 2.
  if sy-subrc = 0.
*   if p_check = 'X'. sav_eronly = p_eronly. endif.
*---Refresh data
    perform refresh_list.
  else. perform action_cancelled. endif.
endform. "CALL_SELECTION_SCREEN
*-----------------------------------------------------------------------
form next_language.
*-For two-language environment it may be hard-coded, e.g.:
* if p_langu = 'E'. p_langu = 'R'. else. p_langu = 'E'. endif.

*-Prevent ABAP Dump
  if lang_len is initial or cant_switch_lang = 'X'.
*--'Cannot switch language'
    message s095.
  else.
*---For multi-language environment it must be evaluated:
    lang_pos = ( lang_pos + 1 ) mod lang_len.
    p_langu = inst_lang+lang_pos(1).

    set language p_langu.
*--'Set language &'
    message s060 with p_langu.
  endif.
endform. "NEXT_LANGUAGE
*-----------------------------------------------------------------------
