ALV-Report von Tabelle NAST

Aus SAP-Wiki
Zur Navigation springenZur Suche springen
*&---------------------------------------------------------------------*
*& Report  ZREBNAST
*& Autor: René Eberstein, Eberstein Consulting
*&---------------------------------------------------------------------*
*& Selektion Tabelle NAST
*&
*&---------------------------------------------------------------------*

REPORT  ZREBNAST.


****************
* DATA & TYPES *
****************
Types: begin of ty_itab,
       kappl type nast-KAPPL,  "Applikation
       objky type nast-OBJKY,  "Objektschlüssel
       kschl type nast-KSCHL,  "Nachrichtenart
       spras type nast-SPRAS,  "Sprache
       parnr type nast-PARNR,  "Partnernummer
       parvw type nast-PARVW,  "Partnerrolle
       erdat type nast-ERDAT,  "Erstellungsdatum
       nacha type nast-nacha,  "Medium
       DATVR type nast-DATVR,  "Datum Verarbeitung
       usnam type nast-usnam,  "Benutzer
       vstat type nast-vstat,  "Versandstatus
       LDEST type nast-LDEST,  "Ausgabegerät
       end of ty_itab.

Types: tty_itab type standard table of ty_itab.

Data: gt_itab type Standard table of ty_itab.

Constants: true  type xfeld value 'X',
           false type xfeld value space.

Tables: nast, sscrfields.


**************
* PARAMETERS *
**************
selection-screen pushbutton /02(17) text user-command yz.

selection-screen skip.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

Select-Options:  s_kappl for nast-kappl,   "Applikation
                 s_objky for nast-objky,   "Objektschlüssel
                 s_kschl for nast-kschl,   "Nachrichtenart
                 s_spras for nast-spras,   "Sprache
                 s_parnr for nast-parnr,   "Partnernummer
                 s_parvw for nast-parvw,   "Partnerrolle
                 s_erdat for nast-erdat,   "Erstellungsdatum
                 s_nacha for nast-nacha,   "Medium
                 s_datvr for nast-datvr,   "Datum Verarbeitung
                 s_usnam for nast-usnam,   "Benutzer
                 s_vstat for nast-vstat,   "Versandstatus
                 s_ldest for nast-ldest.   "Ausgabegerät

SELECTION-SCREEN END OF BLOCK b1.


******************
* INITIALIZATION *
******************
INITIALIZATION.
text = 'TNAPR'.


***********************
* AT SELECTION-SCREEN *
***********************
at selection-screen.
* Programm ZREB_YZ aufrufen bei Push "Auswertung"
  if sscrfields-ucomm = 'YZ'.
    clear sscrfields-ucomm.
    call transaction 'ZREBTNAPR'.
  endif.


**********************
* START-OF-SELECTION *
**********************
start-of-selection.

***********************
* Lese Daten von NAST *
***********************
perform get_data
  changing gt_itab.

************************
* Aufruf der ALV-Liste *
************************
perform alv_itab
    using gt_itab.


**&---------------------------------------------------------------------
**& Form alv_itab
*&---------------------------------------------------------------------
* ALV Function Mod. 'REUSE_ALV_GRID_DISPLAY_LVC'
*----------------------------------------------------------------------
FORM alv_itab
     using p_it_itab type tty_itab.

  type-pools: slis.

  data: l_repid    type sy-repid,
        lt_fcat    type LVC_T_FCAT,
        ls_layout  type LVC_S_LAYO,
*       ls_sort    type LVC_S_SORT,
*       lt_sort    type LVC_T_SORT,
        lt_events  type slis_t_event.

  l_repid = sy-repid.

***************
* Fill Layout *
***************
* ls_layout-zebra      = 'X'.        "Liste wird im Zebra-Look ausgegeben
* LS_LAYOUT-BOX_FNAME  = 'SELKZ'.    "Zeilen der Liste können markiert werden mit Spalte SELKZ
* ls_layout-no_toolbar = 'X'.        "Keine Toolbar
* ls_layout-EXCP_FNAME = 'AMPEL'.    "'1'=rot, '2'=gelb, '3'=grün
* ls_layout-TOTALS_BEF = 'X'.        "Summen vor Einzelsätzen
  LS_LAYOUT-CWIDTH_OPT = 'A'.        "Spaltenbreite wird optimiert

*************
* Fill Sort *
*************
*  CLEAR ls_sort.                    "Liste wird nach Feldern sortiert
*  ls_sort-fieldname = ' '.          "Identische Werte, die übereinander stehen, werden
*  ls_sort-spos      = '1'.          "verbunden und nur der oberste Wert wird angezeigt
*  ls_sort-up        = 'X'.
*  ls_sort-group     = 'UL'.
*  ls_sort-subtot    = 'X'.          "Zwischensummen
*  APPEND ls_sort TO lt_sort.

***************
* Fill Events *
***************
  perform alv_itab_events            "Definition Events und Form-Routinten für
    changing lt_events.              "User-Command, Top-Of-List und Status

*****************
* Fill Fieldcat *
*****************
  perform alv_itab_fcat              "Definition Felder, die ausgegeben werden sollen
    changing lt_fcat.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
  EXPORTING
     i_interface_check          = 'I'
     i_callback_program         = l_repid
     is_layout_lvc              = ls_layout    "Layout ALV
     it_fieldcat_lvc            = lt_fcat      "Tabellen mit Feldern der Liste
    "it_sort_lvc                = lt_sort      "Sortierung
     i_default                  = 'X'          "Default Variante kann abgespeichert werden
     i_save                     = 'A'          "Benutzerabhängige Varianten können gespeichert werden
     IT_EVENTS                  = lt_events    "Event-Tabelle
    "i_screen_start_column      = 10
    "i_screen_start_line        = 10
    "i_screen_end_column        = 50
    "i_screen_end_line          = 50
  TABLES
     t_outtab                   = p_it_itab    "Daten Ausgabetabelle
  EXCEPTIONS
     program_error              = 1
     OTHERS                     = 2.

  IF sy-subrc <> 0.
    message i531(0u) with 'Problem beim Fuba REUSE_ALV_GRID_DISPLAY_LVC'.
  ENDIF.

ENDFORM. " alv_itab


*&---------------------------------------------------------------------*
*&      Form  pf_status_set
*&---------------------------------------------------------------------*
*       Kopie des Standardstatus STANDARD aus der Funktionsgruppe SALV
*----------------------------------------------------------------------*
form alv_itab_pf_status_set
    using rt_extab type slis_t_extab.                       "#EC CALLED

  set pf-status 'STATUS_ITAB' excluding rt_extab.
  set TITLEBAR 'TITLE_ITAB'.

endform.                    "pf_status_set


*&---------------------------------------------------------------------*
*&      Form  alv_itab_events
*&---------------------------------------------------------------------*
*       ALV-Events
*----------------------------------------------------------------------*
form alv_itab_events
   changing p_ct_events type SLIS_T_EVENT.

Data: ls_events   type slis_alv_event.

ls_events-name = 'USER_COMMAND'.
ls_events-form = 'ALV_ITAB_USER_COMMAND'.
append ls_events to p_ct_events.

ls_events-name = 'TOP_OF_PAGE'.
ls_events-form = 'ALV_ITAB_TOP_OF_PAGE'.
append ls_events to p_ct_events.

*ls_events-name = 'PF_STATUS_SET'.
*ls_events-form = 'ALV_ITAB_PF_STATUS_SET'.
*append ls_events to p_ct_events.

endform.                    " alv_itab_events


*&---------------------------------------------------------------------*
*&      Form  alv_itab_fcat
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form alv_itab_fcat
  changing p_ct_fcat type LVC_T_FCAT.

  data: ls_fcat type LVC_S_FCAT.

* Field = Applikation
  ls_fcat-fieldname   = 'KAPPL'.
  ls_fcat-rollname    = 'SNA_KAPPL'.
  ls_fcat-key         = true.
  append ls_fcat to p_ct_fcat.
  clear ls_fcat.

* Field =
  ls_fcat-fieldname   = 'OBJKY'.
  ls_fcat-rollname    = 'NA_OBJKEY'.
  ls_fcat-key         = true.
  append ls_fcat to p_ct_fcat.
  clear ls_fcat.

* Field =
  ls_fcat-fieldname   = 'KSCHL'.
  ls_fcat-rollname    = 'SNA_KSCHL'.
  ls_fcat-key         = true.
  append ls_fcat to p_ct_fcat.
  clear ls_fcat.

* Field =
  ls_fcat-fieldname   = 'SPRAS'.
  ls_fcat-rollname    = 'NA_SPRAS'.
  ls_fcat-key         = true.
  append ls_fcat to p_ct_fcat.
  clear ls_fcat.

* Field =
  ls_fcat-fieldname   = 'PARNR'.
  ls_fcat-rollname    = 'NA_PARNR'.
  ls_fcat-key         = true.
  append ls_fcat to p_ct_fcat.
  clear ls_fcat.

* Field =
  ls_fcat-fieldname   = 'PARVW'.
  ls_fcat-rollname    = 'SNA_PARVW'.
  ls_fcat-key         = true.
  append ls_fcat to p_ct_fcat.
  clear ls_fcat.

* Field =
  ls_fcat-fieldname   = 'ERDAT'.
  ls_fcat-rollname    = 'NA_ERDAT'.
  ls_fcat-key         = true.
  append ls_fcat to p_ct_fcat.
  clear ls_fcat.

* Field =
  ls_fcat-fieldname   = 'NACHA'.
  ls_fcat-rollname    = 'NA_NACHA'.
  ls_fcat-key         = false.
  append ls_fcat to p_ct_fcat.
  clear ls_fcat.

* Field =
  ls_fcat-fieldname   = 'DATVR'.
  ls_fcat-rollname    = 'NA_DATVR'.
  ls_fcat-key         = false.
  append ls_fcat to p_ct_fcat.
  clear ls_fcat.

* Field =
  ls_fcat-fieldname   = 'USNAM'.
  ls_fcat-rollname    = 'USNAM'.
  ls_fcat-key         = false.
  append ls_fcat to p_ct_fcat.
  clear ls_fcat.

* Field =
  ls_fcat-fieldname   = 'VSTAT'.
  ls_fcat-rollname    = 'NA_VSTAT'.
  ls_fcat-key         = false.
  append ls_fcat to p_ct_fcat.
  clear ls_fcat.

* Field =
  ls_fcat-fieldname   = 'LDEST'.
  ls_fcat-rollname    = 'RSPOPNAME'.
  ls_fcat-key         = false.
  append ls_fcat to p_ct_fcat.
  clear ls_fcat.

** Field = Original Language
* ls_fcat-fieldname   = ' '.
* ls_fcat-rollname    = ' '.
* ls_fcat-reptext     = ' '.
* ls_fcat-seltext     = ' '.
* ls_fcat-outputlen   = 10.
* ls_fcat-emphasize   = 'C300'.  "zrebconstants=>cv_color_fcat_gelb
* ls_fcat-edit        = 'X'.
* ls_fcat-do_sum      = 'X'.
* APPEND ls_fcat TO lt_fcat.
* CLEAR ls_fcat.

endform.                    " alv_KNA1_fcat


*&---------------------------------------------------------------------
*& Form USER_COMMAND
*&---------------------------------------------------------------------
*  User Command
*----------------------------------------------------------------------
form alv_itab_user_command                                         "#EC CALLED
  using r_ucomm     type sy-ucomm
        rs_selfield type slis_selfield.

  Data: ls_itab type ty_itab.

  DATA: l_ref_alv TYPE REF TO cl_gui_alv_grid,
        l_valid   TYPE c.                                   "#EC NEEDED

* geänderte Daten holen
* Referenz auf ALV holen
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
       IMPORTING
            e_grid = l_ref_alv.

* Gibt die geänderte ITAB zurück
  CALL METHOD l_ref_alv->check_changed_data
    IMPORTING
      e_valid = l_valid.

* Prüfe ob ein Doppelklick auf eine Zeile erfolgte
  case r_ucomm.

  WHEN 'NEWLINE'.
    CALL METHOD l_ref_alv->APPEND_ROWS
      EXPORTING
        I_ROW_COUNT = 1.

  when '&IC1'.

*   Read line of clicked item
    read table gt_itab index rs_selfield-tabindex
    into ls_itab.

*    case rs_selfield-fieldname.

*
*      when ' '.

*  endcase.
endcase.

endform. " USER_COMMAND_ITAB


*---------------------------------------------------------------------
*      FORM top_of_page
*---------------------------------------------------------------------
*      Fülle Header für ALV-Listen
*----------------------------------------------------------------------
FORM alv_itab_top_of_page.      "#EC CALLED

  DATA: listheader TYPE slis_t_listheader,
        w_listheader TYPE slis_listheader,
        l_datum(10) TYPE c,
        l_lines TYPE i.

* Schreibe Anzahl Datensätze Reporte in Grid Titel
  DESCRIBE TABLE gt_itab LINES l_lines.

* Datum in Ausgabeform bringen
  WRITE sy-datum TO l_datum.

  w_listheader-typ = 'S'.
  w_listheader-key = 'Datum'.
  w_listheader-info = l_datum.
  APPEND w_listheader TO listheader.

  w_listheader-typ = 'S'.
  w_listheader-key = 'Anzahl Datensätze'.
  w_listheader-info = l_lines.
  APPEND w_listheader TO listheader.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
       EXPORTING
           it_list_commentary = listheader.
*          I_LOGO             =
*          I_END_OF_LIST_GRID =

ENDFORM.


*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       Lese Daten von der Tabelle NAST
*----------------------------------------------------------------------*
FORM GET_DATA
  CHANGING PCT_ITAB type tty_itab.

Select *
  into CORRESPONDING FIELDS OF TABLE pct_itab
  from nast
  where
   kappl in s_kappl and "Applikation
   objky in s_objky and "Objektschlüssel
   kschl in s_kschl and "Nachrichtenart
   spras in s_spras and "Sprache
   parnr in s_parnr and "Partnernummer
   parvw in s_parvw and "Partnerrolle
   erdat in s_erdat and "Erstellungsdatum
   nacha in s_nacha and "Medium
   datvr in s_datvr and "Verarbeitungsdatum
   usnam in s_usnam and "Benutzer
   vstat in s_vstat and "Versandstatus
   ldest in s_ldest.    "Ausgabegerät

ENDFORM.                    " GET_DATA