Sends results of tcode SU53 to spool and informs Basis-Administrator(s) with a popup message
* Print results of last authority-check to SAP-spool
* and inform Basis Administrators about this with a popup

report zu53 message-id 26.

data:
  device(4) value 'Z404',                 "SAP printer

  v_cover1  like tsp01_sp0r-rqtitle_v,
  v_mandt   like t000-mandt,
  th_popup  like tfdir-funcname,
  cnt1      type i,
  cnt2      type i,

  begin of usr07key,
    objct like usr07-objct,
    fiel0 like usr07-fiel0,
    fiel1 like usr07-fiel0,
    fiel2 like usr07-fiel0,
    fiel3 like usr07-fiel0,
    fiel4 like usr07-fiel0,
    fiel5 like usr07-fiel0,
    fiel6 like usr07-fiel0,
    fiel7 like usr07-fiel0,
    fiel8 like usr07-fiel0,
    fiel9 like usr07-fiel0,
  end   of usr07key.

*nclude zbc_admins.
constants:
* Please replace these values with your BC-Admins User-IDs:
  bc_adm1 like sy-uname value 'BC_ADM1'  "Basis-Admin 1
, bc_adm2 like sy-uname value 'BC_ADM2'  "Basis-Admin 2
.
*-----------------------------------------------------------------------
initialization.
  perform init.

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

*-----------------------------------------------------------------------
form init.
  th_popup = 'Z_TH_POPUP'.
  select single funcname from tfdir
                         into th_popup
                         where funcname = th_popup.
  if sy-subrc <> 0. th_popup = 'TH_POPUP'. endif.

  concatenate '* ===== ACCESS DENIED ===>' sy-uname
                              into v_cover1 separated by space.
  condense v_cover1.
endform. "INIT
*-----------------------------------------------------------------------
form submit_su53_to_spool.
  submit sapms01g to sap-spool
         destination              device
         copies                   1
         list name               'ADMINFO: SU53 list'
*        list dataset v_dsn
         cover text               v_cover1
*        list authority           v_auth
         immediately             ' '
         keep in spool           'X'
         new list identification 'X'
*        dataset expiration       v_days
         line-count               65
         line-size                255
*        layout                   v_layout
         sap cover page          ' '
         cover page              ' '
         receiver                 bc_adm1
*        department               v_dep
*        archive mode             v_armode
*        archive parameters       v_arparams
         without spool dynpro and return.

endform. "SUBMIT_SU53_TO_SPOOL
*-----------------------------------------------------------------------
form popup_to_admin using l_mandt like usr02-mandt
                          l_bname like usr02-bname
                 changing cnt.

  data: msg like sm04dic-popupmsg, uzeit(8).

  write sy-uzeit to uzeit using edit mask '__:__:__'.
  concatenate
   'SP01: spool for failed authority-check received -'(010)
    uzeit sy-uname
    into msg separated by space.

  call function th_popup
       exporting  client         =  l_mandt
                  user           =  l_bname
                  message        =  msg
                  cut_blanks     = 'X'
       exceptions user_not_found =  1.

  if sy-subrc eq 0. add 1 to cnt. endif.
endform. "POPUP_TO_ADMIN
*-----------------------------------------------------------------------
define send_once.
  if not &1 ge 1.
    perform popup_to_admin using v_mandt &2 changing &1.
  endif.
end-of-definition. "SEND_ONCE
*-----------------------------------------------------------------------
form inform_admins.
* check sy-uname ne bc_adm1 and sy-uname ne bc_adm2.

  clear: cnt1, cnt2.
  select mandt from t000 into v_mandt.
    send_once cnt1 bc_adm1. "Send to admin 1
    send_once cnt2 bc_adm2. "Send to admin 2 too (always)
*   send_once cnt1 bc_adm2. "Send to admin 2 (only if admin 1 not found)
  endselect.

  if cnt1 eq 0 and cnt2 eq 0.
*--'Your request sent to spool (for details see help on this message)'
    message i000 with
'Your request sent to spool. For details see help on this message'(001).
  else.
*--'Your request has been sent to System Administrator'
    message i000 with
      'Your request has been sent to System Administrator'(002).
  endif.
endform. "INFORM_ADMINS
*-----------------------------------------------------------------------
form get_data.
  data ans.

  get parameter id 'XU1' field usr07key.
* get parameter id 'XU2' field usr07val1.
* get parameter id 'XU7' field usr07val2.

  if usr07key-objct = space. "and sy-uname ne bc_adm1. "<--on DEBUG only
    message s000 with
      'All of the checks performed were successful'(003).
  else.

    clear ans.
    call function 'POPUP_TO_DECIDE'
         exporting
           defaultoption  =  1         "Set default to button 1
           textline1      =
             'Prerequisites: you just have received system message'(007)
           textline2      =
             'with explanation on missing authorizations.'(005)
           textline3      =
             'Do you want to send info to system administrator?'(004)
           text_option1   = 'Yes, send!'(008)
           text_option2   = 'No, view only'(009)
           titel          = 'Send info to system administrator'(006)
           start_column   =  10        "X-position on screen
           start_row      =  5         "Y-position on screen
*          cancel_display = 'X'        "space for hide 'CANCEL'
         importing answer =  ans.      "Pressed button here

    case ans.
      when '1'. perform submit_su53_to_spool.
                perform inform_admins.
      when '2'. call transaction 'SU53'.
*     when 'A'.
      when others.
    endcase.

  endif.

endform. "GET_DATA
Beam Back -> ABAP Cafe for Abapers