Z_ALV_SM37

REPORT z_alv_sm37.
*---------------------------------------------------------------------*
* ALV list of jobs - Enhanced SM37                                    *
*---------------------------------------------------------------------*
* Updated 13-May-15  09h00
*---------------------------------------------------------------------*
* Macro definition
DEFINE m_ligne.
  selection-screen :
    begin of line, comment 10(20) v_&1 for field &2.
  select-options &2 for &3.
  selection-screen end of line.
END-OF-DEFINITION.
*---------------------------------------------------------------------*
TABLES:
  sscrfields.                          " Fields on selection screens
*---------------------------------------------------------------------*
TYPE-POOLS:
  slis,                                " ALV types
  icon.                                " Icons
*---------------------------------------------------------------------*
CONSTANTS:
  c_eb9     TYPE syucomm VALUE '&EB9',
  c_refresh TYPE syucomm VALUE '&REFRESH'.
*---------------------------------------------------------------------*
DATA:
  gv_se38 TYPE flag,                   " Authorization for SE38
  gv_sp01 TYPE flag,                   " Authorization for SP01
  gs_dummy_vop TYPE v_op.              " Join from tbtco and tbtcp

TYPES:
  BEGIN OF ty_datajob,
    jobname    TYPE v_op-jobname,      " Background job name
    variant    TYPE tbtcp-variant,     " Name of variant
    status     TYPE v_op-status,       " Status of background job
    progname   TYPE v_op-progname,     " Program name

    reaxserver TYPE v_op-reaxserver,   " Server name
    strtdate   TYPE v_op-strtdate,     " Job start date
    strttime   TYPE v_op-strttime,     " Job start time
    enddate    TYPE v_op-enddate,      " Job end date
    endtime    TYPE v_op-endtime,      " Job end time

    jobcount   TYPE v_op-jobcount,     " Job ID
    stepcount  TYPE v_op-stepcount,    " Job step ID number.
    wpnumber   TYPE v_op-wpnumber,     " Work process number
    sdluname   TYPE v_op-sdluname,     " Initiator job/step scheduling
    listident  TYPE tbtcp-listident,   " Spool ID

    authckman  TYPE v_op-authckman,    " Client
    eventid    TYPE v_op-eventid,      " Background Event Id
  END OF ty_datajob.

TYPES:
* Data to display
  BEGIN OF ty_data.
        INCLUDE TYPE ty_datajob.
TYPES:
    timestamp_beg(8) TYPE p DECIMALS 0,
    timestamp_end(8) TYPE p DECIMALS 0,
    duration         TYPE btcout-duration,
    text             TYPE trdirt-text,
    icon_spool(4)    TYPE c,
    icon_prot(4)     TYPE c,
    tabcolor         TYPE lvc_t_scol,  " Colour
    checkbox         TYPE xfeld,
  END OF ty_data.

TYPES:
  BEGIN OF ty_program_title,
    progname TYPE v_op-progname,
    text(70) TYPE c,
  END OF ty_program_title.

*---------------------------------------------------------------------*
DATA:
  gs_dummy_data TYPE ty_data,
  gt_data  TYPE TABLE OF ty_data,
  gt_langu TYPE TABLE OF sylangu,
  gt_program_title TYPE SORTED TABLE OF ty_program_title
                   WITH UNIQUE KEY progname.

*---------------------------------------------------------------------*
* Select-Options / Parameters
* Client
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 10(20) v_0 FOR FIELD s_client.
SELECT-OPTIONS s_client FOR gs_dummy_vop-authckman DEFAULT sy-mandt
                  MATCHCODE OBJECT ddsef4clnt.
SELECTION-SCREEN END OF LINE.
* Job status
m_ligne 1 s_status gs_dummy_vop-status.                     "#EC NEEDED
* Job name
m_ligne 2 s_jobnam gs_dummy_vop-jobname.                    "#EC NEEDED
* Program
m_ligne 3 s_progrm gs_dummy_vop-progname.                   "#EC NEEDED
SELECTION-SCREEN:
* User
  BEGIN OF LINE, COMMENT 10(20) v_4 FOR FIELD s_sdname.
SELECT-OPTIONS s_sdname FOR gs_dummy_vop-sdluname
                        MATCHCODE OBJECT user_addr.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN:
* Date and time
  BEGIN OF LINE,
  COMMENT 10(20) v_7 FOR FIELD p_datbeg,                    "#EC NEEDED
  POSITION 34.
PARAMETERS p_datbeg TYPE datum DEFAULT sy-datum OBLIGATORY.
SELECTION-SCREEN POSITION 59.
PARAMETERS p_datend TYPE datum DEFAULT sy-datum OBLIGATORY.
SELECTION-SCREEN:
  PUSHBUTTON 72(4) v_09 USER-COMMAND tbbk,
  PUSHBUTTON 76(4) v_10 USER-COMMAND tbck,
  PUSHBUTTON 80(4) v_11 USER-COMMAND tvor.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN:
  BEGIN OF LINE,
  COMMENT 10(20) v_8 FOR FIELD p_timbeg,                    "#EC NEEDED
  POSITION 34.
PARAMETERS p_timbeg TYPE uzeit DEFAULT '000000' OBLIGATORY.
SELECTION-SCREEN POSITION 59.
PARAMETERS p_timend TYPE uzeit DEFAULT '235959' OBLIGATORY.
SELECTION-SCREEN:
  PUSHBUTTON 72(4) v_15 USER-COMMAND hbbk,
  PUSHBUTTON 76(4) v_12 USER-COMMAND hbck,
  PUSHBUTTON 80(4) v_13 USER-COMMAND hvor.
SELECTION-SCREEN END OF LINE.
* Duration
m_ligne 5 s_duratn gs_dummy_data-duration.                  "#EC NEEDED
* Application server
m_ligne 6 s_server gs_dummy_vop-execserver.                 "#EC NEEDED
m_ligne 14 s_evntid gs_dummy_vop-eventid.                   "#EC NEEDED

SELECTION-SCREEN:
  BEGIN OF LINE,
  COMMENT 10(20) v_16 FOR FIELD p_alvlst,                    "#EC NEEDED
  POSITION 34.
PARAMETERS p_alvlst TYPE boole-boole.
SELECTION-SCREEN END OF LINE.

*---------------------------------------------------------------------*
INITIALIZATION.

  v_0 = 'Client              '(000).
  v_1 = 'Status              '(001).
  v_2 = 'Job name            '(002).
  v_3 = 'Program             '(003).
  v_4 = 'User                '(004).
  v_5 = 'Duration            '(005).
  v_6 = 'Server              '(006).
  v_7 = 'Date                '(007).
  v_8 = 'Time                '(008).
  v_09 = icon_page_left.
  v_10 = icon_column_left.
  v_11 = icon_column_right.
  v_12 = icon_column_left.
  v_13 = icon_column_right.
  v_14 = 'Event Id           '(014).
  v_15 = icon_page_left.
  v_16 = 'ALV List'.

  p_timbeg(2) = sy-uzeit(2).

*---------------------------------------------------------------------*
START-OF-SELECTION.

  PERFORM f_read_installed_languages.

* Check authorization for SE38
  PERFORM check_auth_trans USING 'SE38'
                        CHANGING gv_se38.

* Check authorization for SP01
  PERFORM check_auth_trans USING 'SP01'
                        CHANGING gv_sp01.

  PERFORM f_read_data.

*---------------------------------------------------------------------*
END-OF-SELECTION.

  IF p_alvlst IS INITIAL.
*   Switch List -> Grid
    SET PARAMETER ID 'SALV_SWITCH_TO_LIST' FIELD space.
  ELSE.
*   Switch Grid -> List
    SET PARAMETER ID 'SALV_SWITCH_TO_LIST' FIELD wc_x.
  ENDIF.

  PERFORM f_display_data.

*---------------------------------------------------------------------*
*       Form  F_READ_DATA
*---------------------------------------------------------------------*
FORM f_read_data.

  DATA:
    l_langu     TYPE sylangu,        " One-digit SAP language key
    ls_title    TYPE ty_program_title,
    ls_textpool TYPE textpool,
    lt_textpool TYPE TABLE OF textpool,
    ls_data     TYPE ty_data,
    ls_job      TYPE ty_datajob,
    lt_job      TYPE TABLE OF ty_datajob.

  FIELD-SYMBOLS:
    <title> TYPE ty_program_title.

  REFRESH: lt_job, gt_data.

* Read jobs
  SELECT p~jobname
         variant
         o~status
         progname
         reaxserver
         strtdate
         strttime
         enddate
         endtime
         p~jobcount
         p~stepcount
         wpnumber
         p~sdluname
         listident
         authckman
         eventid
    INTO CORRESPONDING FIELDS OF TABLE lt_job
    FROM tbtcp AS p
    JOIN tbtco AS o
      ON p~jobname  = o~jobname
     AND p~jobcount = o~jobcount
   WHERE p~jobname  IN s_jobnam
     AND   progname IN s_progrm
     AND p~sdluname IN s_sdname
     AND   strtdate BETWEEN p_datbeg AND p_datend
     AND o~status   IN s_status
     AND o~status   NE 'S'
     AND o~status   NE 'P'
     AND   reaxserver IN s_server
     AND   authckman  IN s_client
     AND   eventid    IN s_evntid.

  CHECK lt_job[] IS NOT INITIAL.

  LOOP AT lt_job INTO ls_job.
    CLEAR ls_data.
    MOVE-CORRESPONDING ls_job TO ls_data.

    IF ( ls_data-strtdate = p_datbeg AND
         ls_data-strttime < p_timbeg )
        OR
       ( ls_data-strtdate = p_datend AND
         ls_data-strttime > p_timend ).
      DELETE lt_job.
      CONTINUE.
    ENDIF.

    IF ls_data-status = 'R'.
      ls_data-enddate = sy-datum.
      ls_data-endtime = sy-uzeit.
    ENDIF.

    CONVERT DATE ls_data-enddate TIME ls_data-endtime
       INTO TIME STAMP ls_data-timestamp_end TIME ZONE 'UTC   '.

    CONVERT DATE ls_data-strtdate TIME ls_data-strttime
       INTO TIME STAMP ls_data-timestamp_beg TIME ZONE 'UTC   '.

*   Calculate duration
    CALL FUNCTION 'SWI_DURATION_DETERMINE'
      EXPORTING
        start_date = ls_data-strtdate
        end_date   = ls_data-enddate
        start_time = ls_data-strttime
        end_time   = ls_data-endtime
      IMPORTING
        duration   = ls_data-duration.

    IF ls_data-duration NOT IN s_duratn.
      DELETE lt_job.
      CONTINUE.
    ENDIF.

*  Read program title - first Checks in internal table
    READ TABLE gt_program_title WITH KEY progname = ls_data-progname
                               ASSIGNING <title>.
    IF sy-subrc EQ 0.
      ls_data-text =  <title>-text.
    ELSE.
      LOOP AT gt_langu INTO l_langu.

        REFRESH lt_textpool.
        READ TEXTPOOL ls_data-progname
                 INTO lt_textpool LANGUAGE l_langu.
        SORT lt_textpool.
        READ TABLE lt_textpool WITH KEY id = 'R' BINARY SEARCH
                                   INTO ls_textpool.
        IF sy-subrc EQ 0 AND ls_textpool-entry NE space.
          ls_data-text = ls_textpool-entry.
          CLEAR ls_title.
          ls_title-progname = ls_data-progname.
          ls_title-text     = ls_data-text.
          INSERT ls_title INTO TABLE gt_program_title.
          EXIT.                        " Exit LOOP

        ENDIF.
      ENDLOOP.
    ENDIF.

    IF ls_data-listident IS NOT INITIAL.
      ls_data-icon_spool = icon_history.
    ENDIF.

    ls_data-icon_prot = icon_justified.

    APPEND ls_data TO gt_data.

  ENDLOOP.

  PERFORM modify_color_status.

  IF gv_sp01 IS NOT INITIAL.
*   If no authorization for SP01, clear icon_spool
    CLEAR ls_data-icon_spool.
    MODIFY gt_data FROM ls_data
           TRANSPORTING icon_spool
                  WHERE sdluname <> sy-uname
                    AND NOT icon_spool IS INITIAL.
  ENDIF.

ENDFORM.                               " F_READ_DATA
*---------------------------------------------------------------------*
*       FORM MODIFY_COLOR_STATUS                                      *
*---------------------------------------------------------------------*
FORM modify_color_status.

* Field status in red for job aborted
  PERFORM modify_color_status_2 USING 6 'A'.
* Field status in blue for job running
  PERFORM modify_color_status_2 USING 1 'R'.
* Field status in green for Finished jobs
  PERFORM modify_color_status_2 USING 5 'F'.

ENDFORM.                               " MODIFY_COLOR_STATUS
*---------------------------------------------------------------------*
*       FORM MODIFY_COLOR_STATUS_2                                      *
*---------------------------------------------------------------------*
FORM modify_color_status_2 USING u_color  TYPE int1
                                 u_status TYPE char1.

  DATA:
    ls_data     TYPE ty_data,
    ls_tabcolor TYPE lvc_s_scol,
    lt_tabcolor TYPE lvc_t_scol.

  ls_tabcolor-fname     = 'STATUS'.
  ls_tabcolor-color-col = u_color.
  ls_tabcolor-color-int = 1.
  ls_tabcolor-color-inv = 0.
  ls_tabcolor-nokeycol  = wc_x.
  INSERT ls_tabcolor INTO TABLE lt_tabcolor.

  ls_data-tabcolor = lt_tabcolor[].
  MODIFY gt_data FROM ls_data TRANSPORTING tabcolor WHERE status = u_status.

ENDFORM.                               " MODIFY_COLOR_STATUS_2
*---------------------------------------------------------------------*
*      Form  f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.

* Macro definition
  DEFINE m_field.
    add 1 to ls_fieldcat-col_pos.
    ls_fieldcat-fieldname = &1.
    ls_fieldcat-ref_tabname = &2.
    append ls_fieldcat to lt_fieldcat.
  END-OF-DEFINITION.

* Macro definition
  DEFINE m_sort.
    add 1 to ls_sort-spos.
    ls_sort-fieldname = &1.
    ls_sort-down      = wc_x.
    ls_sort-group     = &2.
    append ls_sort to lt_sort.
  END-OF-DEFINITION.

  DATA:
    ls_print      TYPE slis_print_alv,
    ls_fieldcat   TYPE slis_fieldcat_alv,
    lt_fieldcat   TYPE slis_t_fieldcat_alv,
    ls_sort       TYPE slis_sortinfo_alv,
    lt_sort       TYPE slis_t_sortinfo_alv,
    ls_layout     TYPE slis_layout_alv,
    ls_event_exit TYPE slis_event_exit,
    lt_event_exit TYPE slis_t_event_exit.

* Build field catalog
  m_field 'AUTHCKMAN'     'V_OP'.
  m_field 'JOBNAME'       'V_OP'.
  m_field 'ICON_SPOOL'    ''.
  m_field 'ICON_PROT'     ''.
  m_field 'VARIANT'       'TBTCP'.
  m_field 'STATUS'        'V_OP'.
  m_field 'PROGNAME'      'V_OP'.
  m_field 'TEXT'          'TRDIRT'.
  m_field 'REAXSERVER'    'V_OP'.
  m_field 'STRTDATE'      'V_OP'.
  m_field 'STRTTIME'      'V_OP'.
  m_field 'ENDDATE'       'V_OP'.
  m_field 'ENDTIME'       'V_OP'.
  m_field 'TIMESTAMP_BEG' ''.
  m_field 'TIMESTAMP_END' ''.
  m_field 'DURATION'      'BTCOUT'.
  m_field 'JOBCOUNT'      'V_OP'.
  m_field 'STEPCOUNT'     'V_OP'.
  m_field 'SDLUNAME'      'V_OP'.
  m_field 'WPNUMBER'      'V_OP'.
  m_field 'LISTIDENT'     'TBTCP'.
  m_field 'EVENTID'       'V_OP'.

* Timestamp
* ls_fieldcat-edit_mask = '==TSTPS'.
  ls_fieldcat-edit_mask = '==TSTLC'.
  ls_fieldcat-just      = 'L'.
  ls_fieldcat-no_sum    = wc_x.
  MODIFY lt_fieldcat FROM ls_fieldcat
             TRANSPORTING edit_mask just no_sum seltext_s
                    WHERE fieldname(9) EQ 'TIMESTAMP'.

* Duration format HH:MM:SS
  ls_fieldcat-edit_mask = '==SDURA'.
  ls_fieldcat-just      = 'R'.
  MODIFY lt_fieldcat FROM ls_fieldcat
  TRANSPORTING edit_mask just
         WHERE fieldname(5) EQ 'DURATION'
           AND datatype     EQ 'INT4'.

* Icons
  ls_fieldcat-hotspot = wc_x.
  MODIFY lt_fieldcat FROM ls_fieldcat
  TRANSPORTING hotspot WHERE fieldname(5) EQ 'ICON_'.

* No zero
  ls_fieldcat-no_zero = wc_x.
  MODIFY lt_fieldcat FROM ls_fieldcat
  TRANSPORTING no_zero WHERE fieldname EQ 'DURATION'.

  ls_fieldcat-seltext_s   = 'Start time'(013).
  MODIFY lt_fieldcat FROM ls_fieldcat
  TRANSPORTING seltext_s WHERE fieldname EQ 'TIMESTAMP_BEG'.

  ls_fieldcat-seltext_s  = 'End time'(012).
  MODIFY lt_fieldcat FROM ls_fieldcat
  TRANSPORTING seltext_s WHERE fieldname EQ 'TIMESTAMP_END'.

  ls_fieldcat-seltext_s = 'Sp.'.
  ls_fieldcat-seltext_m = 'Spool'(011).
  MODIFY lt_fieldcat FROM ls_fieldcat
  TRANSPORTING seltext_s seltext_m WHERE fieldname EQ 'ICON_SPOOL'.

  ls_fieldcat-seltext_s = 'Pr.'.
  ls_fieldcat-seltext_m = 'Protocol'(010).
  MODIFY lt_fieldcat FROM ls_fieldcat
  TRANSPORTING seltext_s seltext_m WHERE fieldname EQ 'ICON_PROT'.

  ls_fieldcat-no_out = wc_x.
  MODIFY lt_fieldcat FROM ls_fieldcat
  TRANSPORTING no_out WHERE fieldname EQ 'ENDDATE' OR
                            fieldname EQ 'ENDTIME' OR
                            fieldname EQ 'STRTDATE' OR
                            fieldname EQ 'STRTTIME' OR
                            fieldname EQ 'SDLSTRTTM' OR
                            fieldname EQ 'JOBCOUNT' OR
                            fieldname EQ 'WPNUMBER' OR
                            fieldname EQ 'STEPCOUNT' OR
                            fieldname EQ 'LISTIDENT' OR
                            fieldname EQ 'REAXSERVER'.

* Layout
  ls_layout-zebra             = wc_x.
  ls_layout-cell_merge        = wc_x.
  ls_layout-colwidth_optimize = wc_x.
  ls_layout-group_change_edit = wc_x.
  ls_layout-allow_switch_to_list = wc_x.
  ls_layout-box_fieldname = 'CHECKBOX'.
  ls_layout-coltab_fieldname = 'TABCOLOR'.

* Build sort table
  m_sort 'TIMESTAMP_BEG' ''.

* Activate refresh button
  CLEAR ls_event_exit.
  ls_event_exit-ucomm = c_refresh.     " Refresh
  ls_event_exit-after = wc_x.
  APPEND ls_event_exit TO lt_event_exit.

  ls_event_exit-ucomm = c_eb9.         " More
  ls_event_exit-after = wc_x.
  APPEND ls_event_exit TO lt_event_exit.

  ls_print-no_print_selinfos  = wc_x.   " Display no selection infos
  ls_print-no_print_listinfos = wc_x.   " Display no listinfos

* Display the list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = sy-cprog
      i_callback_user_command  = 'USER_COMMAND'
      i_callback_pf_status_set = 'PF_STATUS_SET'
      is_layout                = ls_layout
      is_print                 = ls_print
      it_fieldcat              = lt_fieldcat
      it_sort                  = lt_sort
      it_event_exit            = lt_event_exit
      i_save                   = 'A'
    TABLES
      t_outtab                 = gt_data.

ENDFORM.                               " F_DISPLAY_DATA
*---------------------------------------------------------------------*
*       FORM USER_COMMAND                                             *
*---------------------------------------------------------------------*
FORM user_command USING u_ucomm     TYPE syucomm
                        us_selfield TYPE slis_selfield.     "#EC CALLED

  DATA:
    lt_list  TYPE TABLE OF msxxlist,
    ls_data  TYPE ty_data,
    ls_spool TYPE schedman_spool.

  CASE u_ucomm.
    WHEN '&IC1'.                       " Pick
      READ TABLE gt_data INDEX us_selfield-tabindex INTO ls_data.
      CHECK sy-subrc EQ 0.
      CASE us_selfield-fieldname.
        WHEN 'PROGNAME'.
          IF ls_data-progname IS NOT INITIAL
          AND gv_se38 IS INITIAL.
*           Display program
            EDITOR-CALL FOR REPORT ls_data-progname DISPLAY-MODE.
          ENDIF.
        WHEN 'ICON_SPOOL'.
          IF ls_data-icon_spool IS NOT INITIAL
             AND gv_sp01 IS INITIAL.
            IF sy-subrc EQ 0 AND NOT ls_data-listident IS INITIAL.
              ls_spool-spoolid = ls_data-listident.
*             Display spool
              CALL FUNCTION 'MONI_CALL_SPOOLSHOW'
                EXPORTING
                  ls_spool           = ls_spool
                EXCEPTIONS
                  spool_error        = 1
                  ex_spool_not_found = 2
                  OTHERS             = 3.
            ENDIF.
          ENDIF.
        WHEN 'ICON_PROT'.
*         Display joblog
          CALL FUNCTION 'BP_JOBLOG_SHOW_SM37B'
            EXPORTING
              jobcount                  = ls_data-jobcount
              jobname                   = ls_data-jobname
            EXCEPTIONS
              error_reading_jobdata     = 1
              error_reading_joblog_data = 2
              jobcount_missing          = 3
              joblog_does_not_exist     = 4
              joblog_is_empty           = 5
              joblog_show_canceled      = 6
              jobname_missing           = 7
              job_does_not_exist        = 8
              no_joblog_there_yet       = 9
              no_show_privilege_given   = 10
              OTHERS                    = 11.
          IF sy-subrc <> 0.
            MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          ENDIF.
        WHEN 'SDLUNAME'.
*         Display user
          CALL FUNCTION 'SUSR_SHOW_USER_DETAILS'
            EXPORTING
              bname = ls_data-sdluname.                     "#EC
        WHEN 'VARIANT'.
          IF ls_data-variant IS NOT INITIAL.
*           Display variant
            CALL FUNCTION 'RS_VARIANT_DISPLAY'
              EXPORTING
                report               = ls_data-progname     "#EC
                variant              = ls_data-variant      "#EC
                action               = 'VSHO'
              EXCEPTIONS
                no_report            = 1
                report_not_existent  = 2
                report_not_supplied  = 3
                variant_not_existent = 4
                variant_not_supplied = 5
                variant_protected    = 6
                OTHERS               = 7.
            IF sy-subrc <> 0.
              MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
                    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

            ENDIF.
          ENDIF.
        WHEN 'TIMESTAMP_BEG'.
          PERFORM call_stad USING ls_data.
      ENDCASE.
    WHEN c_refresh.
      PERFORM f_read_data.
      us_selfield-refresh = wc_x.
    WHEN c_eb9.
*     Get Server List
      CALL FUNCTION 'TH_SERVER_LIST'
        TABLES
          list           = lt_list
        EXCEPTIONS
          no_server_list = 1
          OTHERS         = 2.
      IF sy-subrc IS INITIAL.
        IF lines( lt_list ) EQ 1.
          CALL TRANSACTION 'SM50'.
        ELSE.
          CALL TRANSACTION 'SM51'.
        ENDIF.
      ENDIF.
  ENDCASE.

ENDFORM.                               " USER_COMMAND
*---------------------------------------------------------------------*
*       FORM PF_STATUS_SET                                            *
*---------------------------------------------------------------------*
FORM pf_status_set USING ut_extab TYPE slis_t_extab.        "#EC CALLED

* Display refresh button
  DELETE ut_extab WHERE fcode = c_refresh OR fcode = c_eb9.

  SET PF-STATUS 'STANDARD_FULLSCREEN' OF PROGRAM 'SAPLKKBL'
      EXCLUDING ut_extab.

ENDFORM.                               " PF_STATUS_SET
*---------------------------------------------------------------------*
AT SELECTION-SCREEN.

  IF sscrfields-ucomm = 'TBBK'.
    IF p_datbeg IS NOT INITIAL.
      SUBTRACT 7 FROM p_datbeg.
    ELSE.
      p_datbeg = sy-datum.
    ENDIF.
  ELSEIF sscrfields-ucomm = 'TBCK'.
    IF p_datbeg IS NOT INITIAL.
      SUBTRACT 1 FROM p_datbeg.
    ELSE.
      p_datbeg = sy-datum.
    ENDIF.
  ELSEIF sscrfields-ucomm = 'TVOR'.
    IF p_datbeg IS NOT INITIAL.
      ADD 1 TO p_datbeg.
      IF p_datbeg > sy-datum.
        p_datbeg = sy-datum.
      ENDIF.
    ELSE.
      p_datbeg = sy-datum.
    ENDIF.
  ELSEIF sscrfields-ucomm = 'HBBK'.
    p_timbeg = 0.
  ELSEIF sscrfields-ucomm = 'HBCK'.
    IF NOT ( p_timbeg IS INITIAL AND p_datbeg IS INITIAL ).
      IF p_timbeg >= 3600.
        SUBTRACT 3600 FROM p_timbeg.
      ELSE.
        SUBTRACT 1 FROM p_datbeg.
        p_timbeg = p_timbeg + ( 3600 * 23 ).
      ENDIF.
    ELSE.
      p_timbeg = sy-uzeit.
    ENDIF.
  ELSEIF sscrfields-ucomm = 'HVOR'.
    IF NOT ( p_timbeg IS INITIAL AND p_datbeg IS INITIAL ).
      IF p_datbeg >= sy-datum AND p_timbeg >= sy-uzeit.
        p_timbeg = sy-uzeit.
      ELSEIF p_timbeg > 82800.
        ADD 1 TO p_datbeg.
        p_timbeg = p_timbeg - ( 3600 * 23 ).
      ELSE.
        ADD 3600 TO p_timbeg.
      ENDIF.
    ELSE.
      p_timbeg = sy-uzeit.
    ENDIF.
  ENDIF.

  IF p_datend < p_datbeg.
*   First date is later than second date
    MESSAGE e400(bt).
  ENDIF.

  IF p_datend = p_datbeg AND
     p_timend < p_timbeg.
*   Begin time is after end time
    MESSAGE e575(xt).
  ENDIF.

*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_server-low.

  PERFORM show_target_server CHANGING s_server-low.

*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_server-high.

  PERFORM show_target_server CHANGING s_server-high.

*---------------------------------------------------------------------*
*      Form  show_target_server
*---------------------------------------------------------------------*
FORM show_target_server CHANGING u_server TYPE btcsrvname.

  DATA l_server TYPE msxxlist-name.

* Select application server
  CALL FUNCTION 'TH_SELECT_SERVER'
    IMPORTING
      server                  = l_server
    EXCEPTIONS
      no_server_list_received = 1
      no_server_selected      = 2
      OTHERS                  = 3.
  IF sy-subrc > 2.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  u_server = l_server.

ENDFORM.                               " SHOW_TARGET_SERVER
*--------------------------------------------------------------------*
*      Form  F_READ_INSTALLED_LANGUAGES
*--------------------------------------------------------------------*
FORM f_read_installed_languages.

  CONSTANTS:
    c_param(40) VALUE 'zcsa/installed_languages'.

  DATA:
    l_len TYPE i,
    l_off TYPE i,
    l_lang(50) TYPE c.                 " Installed languages

* Installed languages
  CALL 'C_SAPGPARAM' ID 'NAME'  FIELD c_param
                     ID 'VALUE' FIELD l_lang.

  FIELD-SYMBOLS <f> TYPE char1.

  l_len = strlen( l_lang ).
  DO l_len TIMES.
    l_off = sy-index - 1.
    ASSIGN l_lang+l_off(1) TO <f>.
    CHECK <f> NE space.
    APPEND <f> TO gt_langu.
  ENDDO.

* Logon language on top of gt_langu
  DELETE gt_langu WHERE table_line = sy-langu.
  INSERT sy-langu INTO gt_langu INDEX 1.

ENDFORM.                               " F_READ_INSTALLED_LANGUAGES
*---------------------------------------------------------------------*
*       FORM CHECK_AUTH_TRANS                                         *
*---------------------------------------------------------------------*
FORM check_auth_trans USING u_tcode TYPE sytcode
                   CHANGING u_flag  TYPE flag.

  DATA l_subrc TYPE sysubrc.

* Authority-check (object assigned by TSTCA)
  CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
    EXPORTING
      tcode  = u_tcode
    EXCEPTIONS
      ok     = 0
      not_ok = 1
      OTHERS = 2.
  IF sy-subrc NE 0.
    u_flag = wc_x.
    RETURN.
  ENDIF.

* Authority-check (object S_TCODE)
  CALL FUNCTION 'SUSR_AUTHORITY_CHECK_S_TCODE'
    EXPORTING
      tcode = u_tcode
    IMPORTING
      rc    = l_subrc.
  IF l_subrc NE 0.
    u_flag = wc_x.
    RETURN.
  ENDIF.

ENDFORM.                               " CHECK_AUTH_TRANS
*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_evntid-low.

  PERFORM f_show_eventid USING s_evntid-low 'S_EVENTID-LOW'.

*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_evntid-high.

  PERFORM f_show_eventid USING s_evntid-high 'S_EVENTID-HIGH'.

*---------------------------------------------------------------------*
*       FORM f_show_eventid                                           *
*---------------------------------------------------------------------*
*  -->  U_EVENTID                                                     *
*  -->  U_FIELDNAME                                                   *
*---------------------------------------------------------------------*
FORM f_show_eventid USING u_eventid TYPE btceventid
                          u_fieldname TYPE dynfnam.

  DATA:
    ls_return      TYPE ddshretval,
    lt_return      TYPE dmc_ddshretval_table,
    lt_eventid_hlp TYPE TABLE OF btcevthtbl.

* Read user event id
  SELECT eventid FROM btcuev INTO TABLE lt_eventid_hlp.

* Read system event id
  SELECT eventid FROM btcsev APPENDING TABLE lt_eventid_hlp.

  SORT lt_eventid_hlp BY eventid ASCENDING.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'EVENTID'
      dynprofield     = u_fieldname
      value_org       = 'S'
    TABLES
      value_tab       = lt_eventid_hlp
      return_tab      = lt_return
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  CHECK lt_return[] IS NOT INITIAL.
  READ TABLE lt_return INDEX 1 INTO ls_return.
  u_eventid = ls_return-fieldval.

ENDFORM.                             " F_SHOW_EVENTID
*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_status-low.

  PERFORM f_show_status USING s_status-low 'S_STATUS-LOW'.

*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_status-high.

  PERFORM f_show_status USING s_status-high 'S_STATUS-HIGH'.

*---------------------------------------------------------------------*
*       FORM f_show_status                                            *
*---------------------------------------------------------------------*
*  -->  U_STATUS                                                      *
*  -->  U_FIELDNAME                                                   *
*---------------------------------------------------------------------*
FORM f_show_status USING u_status TYPE btcstatus
                         u_fieldname TYPE dynfnam.

  TYPES:
    BEGIN OF ty_status,
      status TYPE btcstatus,
      libel_status TYPE rstxt20,
    END OF ty_status.

  DATA:
    ls_return     TYPE ddshretval,
    lt_return     TYPE dmc_ddshretval_table,
    ls_status_hlp TYPE ty_status,
    lt_status_hlp TYPE TABLE OF ty_status.

  ls_status_hlp-status = 'A'.
  ls_status_hlp-libel_status = 'Aborted'.
  APPEND ls_status_hlp TO lt_status_hlp.

  ls_status_hlp-status = 'F'.
  ls_status_hlp-libel_status = 'Finished'.
  APPEND ls_status_hlp TO lt_status_hlp.

  ls_status_hlp-status = 'R'.
  ls_status_hlp-libel_status = 'Running'.
  APPEND ls_status_hlp TO lt_status_hlp.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'STATUS'
      dynprofield     = u_fieldname
      value_org       = 'S'
    TABLES
      value_tab       = lt_status_hlp
      return_tab      = lt_return
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  CHECK lt_return[] IS NOT INITIAL.
  READ TABLE lt_return INDEX 1 INTO ls_return.
  u_status = ls_return-fieldval.

ENDFORM.                               " F_SHOW_STATUS
*---------------------------------------------------------------------*
*      Form  CALL_STAD
*---------------------------------------------------------------------*
FORM call_stad USING ps_data TYPE ty_data.

  SUBMIT rsstat26
    WITH rmode    = 'c'
    WITH rmandt   = ps_data-authckman
    WITH rstartti = ps_data-strttime
    WITH rday     = ps_data-strtdate
    WITH rreadti  = ps_data-duration
    WITH ruser    = ps_data-sdluname
*   WITH rtcodf   = tcode
    WITH rprogf   = ps_data-progname
*   WITH ronly    = g_sel_para-instance
     AND RETURN.

ENDFORM.                               " CALL_STAD
************** END OF PROGRAM Z_ALV_SM37 ******************************
Comments