ZHR_REP_YEAR – Jahresübersicht der An- und Abwesenheiten pro MA tabellarisch

Hier ein sehr praktisches Programm zum Anzeigen der Abwesenheiten mit Verwendung eines ALV Grids, das mir so gefallen hat, das ich es aufnehmen mußte.

Es verwendet den FuBa REUSE_ALV_GRID_DISPLAY, ist aber OO aufgebaut.

Der Aufwand, es lauffähig zu machen, ist entsprechend groß, müssen doch Datenelemente und Typen im Datadictionary erzeugt werden.

Ich bevorzuge hier die Definition im Programm, hier sind zwar globale Änderungen dann nicht rasch möglich, die 30 jährige Erfahrung hat aber gezeigt, dass die globalen Änderungen nie stattfinden.

Und ein Z-Programm wird sowieso immer separat angesehen werden.

Wenn ich mal viel Zeit habe, werde ich es umbauen, sodass es als Stand-Alone Programm auch funktioniert.

report zhr_rep_summary_year.

data lv_tabname type tabname.
data lt_fcat_out type slis_t_fieldcat_alv.
data lt_data type zhr_summary_day_t.
data lt_wdays type table of rke_dat.
data lt_kdays type table of rke_dat.
data lt_adays type table of rke_dat.
data lt_month type table of t247.
data lv_grid_title type  lvc_title.
data lv_emnam type emnam.
data lv_act_plvar type plvar.
data lv_isall type xfeld.
data lt_2006 type table of pa2006.
data lt_2001 type table of pa2001.
data lv_datab type sydatum.
data lv_datbi type sydatum.
data lv_resturlaub type p DECIMALS 1.
data lv_urlgep type p DECIMALS 1.
data lt_listheader type slis_t_listheader.
data lv_persa type persa.
data lv_btrtl type btrtl.

selection-screen begin of block all with frame title text-001.
parameters: p_pernr type pernr_d obligatory matchcode object prem.
parameters: p_year type jahr4 obligatory.
parameters: p_factid type wfcid default 'AT' no-display.
selection-screen end of block all.

class application definition create private.

  public section.

    class-methods fill_default.

    class-methods run.

    class-methods top_of_page.

    class-methods get_calender
      changing c_data  type zhr_summary_day_t
               c_wdays type zhr_rke_dat
               c_kdays type zhr_rke_dat
               c_month type ftps_web_month_t.

    class-methods get_pernr_data
      changing c_data type zhr_summary_day_t.

    class-methods read_fcat
      changing lv_tabname type tabname
               c_fcat     type slis_t_fieldcat_alv.

    class-methods output
      changing c_data type zhr_summary_day_t
               c_fcat type slis_t_fieldcat_alv.

endclass.

class application implementation.

  method fill_default.

    if p_pernr is initial.
      select single pernr from pa0105 into p_pernr
              where usrid = sy-uname
                and usrty = '0001'.
    endif.
    if p_year is initial.
      p_year = sy-datum(4).
    endif.
  endmethod.

  method run.

    data lt_result_tab_o type table of swhactor.
    data lt_obj_tab type table of hrobject.

* Prüfen ob Personalnummer gültig
    call function 'RP_CHECK_PERNR'
      exporting
        beg               = sy-datum
        pnr               = p_pernr
      importing
        name              = lv_emnam
        persa             = lv_persa
        personnel_subarea = lv_btrtl
      exceptions
        data_fault        = 1
        person_not_active = 2
        person_unknown    = 3
        exit_fault        = 4
        pernr_missing     = 5
        date_missing      = 6
        others            = 7.

    if sy-subrc is initial.

*Strukturelle Berechtigungsprüfung
      call function 'RH_GET_ACTIVE_WF_PLVAR'
        importing
          act_plvar = lv_act_plvar
        exceptions
          others    = 1.

      if sy-subrc is not initial.
        message e300(5w).
      else.

        call function 'ZHR_GET_STRUC_AUTHORITY'
          exporting
            i_uname   = sy-uname
          importing
            e_is_all  = lv_isall
          tables
            t_obj_tab = lt_obj_tab.

        delete lt_obj_tab where otype ne 'P'.

        sort lt_obj_tab by objid.

        read table lt_obj_tab with key objid = p_pernr binary search transporting no fields.

        if sy-subrc is initial or lv_isall is not initial.

          lv_tabname = 'ZHR_SUMMARY_YEAR'.

          application=>get_calender( changing c_data = lt_data
                                              c_wdays = lt_wdays
                                              c_kdays = lt_kdays
                                              c_month = lt_month ).

          application=>get_pernr_data( changing c_data = lt_data ).

          application=>read_fcat( changing lv_tabname = lv_tabname
                                           c_fcat = lt_fcat_out ).

          application=>output( changing c_data = lt_data
                                        c_fcat  = lt_fcat_out ).
        else.
          message i003(hrpad00_erd) with p_pernr.
*   Keine Berechtigung für Personalnummer &
        endif.
      endif.
    else.
      message id sy-msgid type 'I' number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.

  endmethod.
  method top_of_page.

    data lv_rest(6) type c.
    data lv_gepl(6) type c.
    data char_pernr type char6.

    write lv_resturlaub to lv_rest.
    write lv_urlgep to lv_gepl.

    append initial line to lt_listheader assigning field-symbol(<listheader>).
    <listheader>-typ = 'H'.
    concatenate '(' p_pernr+4(4) ')' into char_pernr.
    concatenate: lv_emnam char_pernr into <listheader>-info separated by space.
    append initial line to lt_listheader assigning <listheader>.
    <listheader>-typ = 'A'.
    concatenate text-101 p_year into <listheader>-info separated by space.
    append initial line to lt_listheader assigning <listheader>.
    <listheader>-typ = 'A'.
    concatenate text-102 lv_rest into <listheader>-info separated by space.
    append initial line to lt_listheader assigning <listheader>.
    <listheader>-typ = 'A'.
    concatenate text-103 lv_gepl into <listheader>-info separated by space.

    call function 'REUSE_ALV_COMMENTARY_WRITE'
      exporting
        it_list_commentary = lt_listheader.
  endmethod.
  method get_calender.

    data lv_month type fcmnr.
    data lv_color type line of slis_t_specialcol_alv.
    data lv_shorttext type kurzt.
    data lv_data type zhr_summary_day_l.
    data lv_fieldname type name_komp.
    data lt_tfait type table of tfait.
    data lt_wdays_cust type table of zhr_wdays_cust.

    field-symbols <fieldname> type any.

    concatenate p_year '0101' into lv_datab.
    concatenate p_year '1231' into lv_datbi.

    call function 'MONTH_NAMES_GET'
      tables
        month_names           = lt_month
      exceptions
        month_names_not_found = 1
        others                = 2.

    call function 'RKE_SELECT_FACTDAYS_FOR_PERIOD'
      exporting
        i_datab               = lv_datab
        i_datbi               = lv_datbi
        i_factid              = 'W8'
      tables
        eth_dats              = c_kdays
      exceptions
        date_conversion_error = 1
        others                = 2.

    call function 'RKE_SELECT_FACTDAYS_FOR_PERIOD'
      exporting
        i_datab               = lv_datab
        i_datbi               = lv_datbi
        i_factid              = p_factid
      tables
        eth_dats              = c_wdays
      exceptions
        date_conversion_error = 1
        others                = 2.

    select * from tfait into table lt_tfait
             where spra = sy-langu
               and jahr = p_year.

    select * from zhr_wdays_cust into table lt_wdays_cust.

    loop at c_kdays assigning field-symbol(<kdays>).
      clear: lv_shorttext.

      if lv_month ne <kdays>-periodat+4(2).
        if lv_month is not initial.
          append lv_data to c_data.
        endif.
        clear: lv_data.
        read table lt_month assigning field-symbol(<month>)
                   with key mnr = <kdays>-periodat+4(2).
        lv_data-month = <month>-ltx.

      endif.

      call function 'ISH_GET_WEEKDAY_NAME'
        exporting
          date        = <kdays>-periodat
          language    = sy-langu
        importing
          shorttext   = lv_shorttext
        exceptions
          calendar_id = 1
          date_error  = 2
          not_found   = 3
          wrong_input = 4
          others      = 5.

      concatenate 'DAY_' <kdays>-periodat+6(2) into lv_color-fieldname.
      concatenate 'LV_DATA-DAY_' <kdays>-periodat+6(2) into lv_fieldname.

      assign (lv_fieldname) to <fieldname>.

      read table c_wdays with key periodat = <kdays>-periodat transporting no fields.
      if sy-subrc is not initial.
        read table lt_tfait with key von = <kdays>-periodat transporting no fields.
        if sy-subrc is initial.
          read table lt_wdays_cust assigning field-symbol(<wdays>)
                with key wday = 'AFS'.
        else.
          read table lt_wdays_cust assigning <wdays>
                with key wday = lv_shorttext.
          if <wdays>-is_wday is not initial.
            read table lt_wdays_cust assigning <wdays>
                  with key wday = 'FTG'.
          endif.
        endif.
      else.
        read table lt_wdays_cust assigning <wdays>
              with key wday = lv_shorttext.
      endif.

      lv_color-color-col = <wdays>-col_col.
      lv_color-color-int = <wdays>-col_int.
      lv_color-color-inv = <wdays>-col_inv.
      <fieldname> = <wdays>-text.
      append lv_color to lv_data-cellcol.

      lv_month = <kdays>-periodat+4(2).
    endloop.

    append lv_data to c_data.

  endmethod.

  method get_pernr_data.

    data lt_pa type table of pa2001.
    data lv_data type zhr_summary_day_l.
    data lv_index type sytabix.
    data lv_index2 type sytabix.
    data lv_fieldname type name_komp.
    data lv_field type name_komp.
    data lv_alv_color type zca_alv_color.
    data lt_awart type table of zhr_awart_cust.
    data lt_wdays type zhr_rke_dat.
    data lt_t554s type table of t554s.
    data lt_t5a4q type table of t5a4q.
    data lt_error	type table of	edimessage.
    data lv_moabw type moabw.

    field-symbols <fieldname> type any.
    field-symbols <field> type any.

    select * from zhr_awart_cust into table lt_awart.

    select * from pa2001 into table lt_pa
                where pernr = p_pernr.

    select * from pa2002 appending corresponding fields of table lt_pa
             where pernr = p_pernr.

    if lt_pa[] is not initial.

      loop at lt_pa assigning field-symbol(<pa>).

        clear: lt_adays[].

        call function 'RKE_SELECT_FACTDAYS_FOR_PERIOD'
          exporting
            i_datab               = <pa>-begda
            i_datbi               = <pa>-endda
            i_factid              = p_factid
          tables
            eth_dats              = lt_adays
          exceptions
            date_conversion_error = 1
            others                = 2.

        loop at lt_adays assigning field-symbol(<adays>) where periodat(4) = p_year.

          lv_index = <adays>-periodat+4(2).

          read table c_data into lv_data index lv_index.

          concatenate 'LV_DATA-DAY_' <adays>-periodat+6(2) into lv_fieldname.
          concatenate 'DAY_' <adays>-periodat+6(2) into lv_field.

          assign (lv_fieldname) to <fieldname>.
          assign lv_field to <field>.

          read table lv_data-cellcol into lv_alv_color with key fieldname = <field>.
          lv_index2 = sy-tabix.

          read table lt_awart assigning field-symbol(<awart>)
                with key awart = <pa>-awart.
          if sy-subrc is initial.

            <fieldname> = <awart>-text.
            lv_alv_color-color-col = <awart>-col_col.
            lv_alv_color-color-int = <awart>-col_int.
            lv_alv_color-color-inv = <awart>-col_inv.

            modify lv_data-cellcol from lv_alv_color index lv_index2.
          endif.

          modify lv_data-cellcol from lv_alv_color index lv_index2.
          modify c_data from lv_data index lv_index.

        endloop.

      endloop.
    endif.

    call function 'HRGPBS_SMP_SSP_GET_MOABW'
      exporting
        p_werks      = lv_persa
        p_btrtl      = lv_btrtl
      tables
        p_error      = lt_error
      changing
        p_moabw      = lv_moabw
      exceptions
        t001p_failed = 1
        others       = 2.

    select * from t5a4q into table lt_t5a4q
             where moabw = lv_moabw
               and kzabw = '1'. "Gebühren- / Sonderurlaub

    select * from t554s into table lt_t554s
              for all entries in lt_t5a4q
              where moabw = lv_moabw
                and absty = lt_t5a4q-absty
                and begda le sy-datum
                and endda ge sy-datum.

    select * from pa2006 into table lt_2006
             where pernr = p_pernr.

    loop at lt_2006 assigning field-symbol(<pa2006>).
      lv_resturlaub = lv_resturlaub + <pa2006>-anzhl - <pa2006>-kverb.
    endloop.

    select * from pa2001 into table lt_2001
              for all entries in lt_t554s
             where pernr = p_pernr
               and begda gt sy-datum
               and subty = lt_t554s-subty.

    loop at lt_2001 assigning field-symbol(<pa2001>).
      lv_urlgep = lv_urlgep + <pa2001>-abrtg.
    endloop.

  endmethod.

  method read_fcat.

    call function 'REUSE_ALV_FIELDCATALOG_MERGE'
      exporting
        i_structure_name = lv_tabname
      changing
        ct_fieldcat      = c_fcat[].

    loop at c_fcat assigning field-symbol(<fcat>) where fieldname(3) = 'DAY'.
      <fcat>-reptext_ddic = <fcat>-seltext_l = <fcat>-seltext_m = <fcat>-seltext_s = <fcat>-fieldname+4(2).
    endloop.

  endmethod.

  method output.

    data ls_layout type slis_layout_alv.
    data lv_repid type syrepid value 'ZHR_REP_SUMMARY_YEAR'.

    ls_layout-colwidth_optimize = abap_false.
    ls_layout-zebra = abap_false.
    ls_layout-coltab_fieldname  = 'CELLCOL'.

    call function 'REUSE_ALV_GRID_DISPLAY'
      exporting
        i_callback_program     = lv_repid
        i_grid_title           = lv_grid_title
        it_fieldcat            = c_fcat
        is_layout              = ls_layout
        i_callback_top_of_page = 'TOP_OF_PAGE'
      tables
        t_outtab               = c_data
      exceptions
        program_error          = 1
        others                 = 2.

  endmethod.

endclass.

start-of-selection.
  application=>run( ).

at selection-screen output.
  application=>fill_default( ).

form top_of_page.

  application=>top_of_page( ).

endform.

Typendefinitionen: