ALV-Report von Tabelle TNAPR
Aus SAP-Wiki
Zur Navigation springenZur Suche springen
Die Tabelle TNAPR im beinhaltet Daten zur Outputsteuerung von Nachrichten und sie wird sehr häufig von Formularentwicklern genutzt, um z. B zu einer gegebenen Nachrichtenart das passende Druckprogramm und Formular anzusateuern.
Dies wurde über die Nachrichtensteuerung im Customizing eingestellt.
*&---------------------------------------------------------------------* *& Report ZREBTNAPR *& *&---------------------------------------------------------------------* *& Autor: René Eberstein, Eberstein Consulting *& Liest die Tabelle TNAPR und gibt sie in ALV-Liste aus *&---------------------------------------------------------------------* REPORT ZREBTNAPR.
**************** * DATA & TYPES * **************** Types: begin of ty_itab, kschl type tnapr-kschl, nacha type tnapr-nacha, kappl type tnapr-kappl, pgnam type tnapr-pgnam, ronam type tnapr-ronam, fonam type tnapr-fonam, sform type tnapr-sform, type type tnapr-formtype, 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: tnapr.
************** * PARAMETERS * ************** SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. Select-Options: s_kschl for tnapr-kschl. SELECTION-SCREEN END OF BLOCK b1.
*********************** * AT SELECTION-SCREEN * *********************** at selection-screen.
********************** * START-OF-SELECTION * ********************** start-of-selection. ************ * GET_DATA * ************ 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 = Nachrichtenart ls_fcat-fieldname = 'KSCHL'. ls_fcat-rollname = 'NA_KSCHL'. ls_fcat-key = true. append ls_fcat to p_ct_fcat. clear ls_fcat. * Field = Applikation ls_fcat-fieldname = 'KAPPL'. ls_fcat-rollname = 'KAPPL'. ls_fcat-key = true. append ls_fcat to p_ct_fcat. clear ls_fcat. * Field = Sendemedium Nachricht ls_fcat-fieldname = 'NACHA'. ls_fcat-rollname = 'NA_NACHA'. ls_fcat-key = true. append ls_fcat to p_ct_fcat. clear ls_fcat. * Field = Druckprogramm ls_fcat-fieldname = 'PGNAM'. ls_fcat-rollname = 'NA_PGNAM'. ls_fcat-key = false. append ls_fcat to p_ct_fcat. clear ls_fcat. * Field = Form-Routine ls_fcat-fieldname = 'RONAM'. ls_fcat-rollname = 'NA_RONAM'. ls_fcat-key = false. append ls_fcat to p_ct_fcat. clear ls_fcat. * Field = SAPScript ls_fcat-fieldname = 'FONAM'. ls_fcat-rollname = 'TDFORM'. ls_fcat-key = false. ls_fcat-emphasize = 'C300'. "zrebconstants=>cv_color_fcat_gelb append ls_fcat to p_ct_fcat. clear ls_fcat. * Field = Smart Forms/Adobe Forms ls_fcat-fieldname = 'SFORM'. ls_fcat-rollname = 'NA_FNAME'. ls_fcat-key = false. ls_fcat-emphasize = 'C300'. "zrebconstants=>cv_color_fcat_gelb append ls_fcat to p_ct_fcat. clear ls_fcat. * Field = Typ (1 = Smart Forms, 2 = Adobe Forms) ls_fcat-fieldname = 'TYPE'. ls_fcat-rollname = 'NA_FORMTYPE'. 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. DATA: ls_bdcdata TYPE bdcdata, lt_bdcdata TYPE TABLE OF bdcdata, lt_itab_msg TYPE TABLE OF bdcmsgcoll. "#EC NEEDED case ls_itab-type. * Smart Forms/SAPscript when '1' or space. if ls_itab-fonam is initial and ls_itab-sform is initial. message i531(0u) with 'Kein Formular in Nachrichtenart vorhanden'(002). return. endif. * Smart Forms if ls_itab-sform is not initial. * Einstiegsbildschirm aufrufen ls_bdcdata-program = 'SAPMSSFO'. ls_bdcdata-dynpro = '0100'. ls_bdcdata-dynbegin = 'X'. APPEND ls_bdcdata TO lt_bdcdata. CLEAR ls_bdcdata. "Bildschirm füllen ls_bdcdata-fnam = 'RB_SF'. ls_bdcdata-fval = 'X'. APPEND ls_bdcdata TO lt_bdcdata. CLEAR ls_bdcdata. ls_bdcdata-fnam = 'SSFSCREEN-FNAME'. ls_bdcdata-fval = ls_itab-sform. APPEND ls_bdcdata TO lt_bdcdata. * OK-Code übergeben CLEAR ls_bdcdata. ls_bdcdata-fnam = 'BDC_OKCODE'. ls_bdcdata-fval = '=DISPLAY'. APPEND ls_bdcdata TO lt_bdcdata. * Transaktion ausführen CALL TRANSACTION 'SMARTFORMS' USING lt_bdcdata MODE 'E' "E = Stoppen nur bei Error, A = Anzeige (für Test) MESSAGES INTO lt_itab_msg. "Fehlertabelle endif. if ls_itab-fonam is not initial. * Einstiegsbildschirm aufrufen ls_bdcdata-program = 'SAPMSSCF'. ls_bdcdata-dynpro = '1101'. ls_bdcdata-dynbegin = 'X'. APPEND ls_bdcdata TO lt_bdcdata. CLEAR ls_bdcdata. "Bildschirm füllen ls_bdcdata-fnam = 'RSSCF-TDFORM'. ls_bdcdata-fval = ls_itab-fonam. APPEND ls_bdcdata TO lt_bdcdata. CLEAR ls_bdcdata. ls_bdcdata-fnam = 'RSSCF-TDSPRAS'. ls_bdcdata-fval = sy-langu. APPEND ls_bdcdata TO lt_bdcdata. * OK-Code übergeben CLEAR ls_bdcdata. ls_bdcdata-fnam = 'BDC_OKCODE'. ls_bdcdata-fval = '=SHOW'. APPEND ls_bdcdata TO lt_bdcdata. * Transaktion ausführen CALL TRANSACTION 'SE71' USING lt_bdcdata MODE 'E' "E = Stoppen nur bei Error, A = Anzeige (für Test) MESSAGES INTO lt_itab_msg. "Fehlertabelle endif. * Adobe Forms when '2'. * Einstiegsbildschirm aufrufen ls_bdcdata-program = 'SAPLFPUIFB'. ls_bdcdata-dynpro = '1000'. ls_bdcdata-dynbegin = 'X'. APPEND ls_bdcdata TO lt_bdcdata. CLEAR ls_bdcdata. "Bildschirm füllen ls_bdcdata-fnam = 'D_FORM_RADIO'. ls_bdcdata-fval = 'X'. APPEND ls_bdcdata TO lt_bdcdata. CLEAR ls_bdcdata. ls_bdcdata-fnam = 'D_FORM_NAME'. ls_bdcdata-fval = ls_itab-sform. APPEND ls_bdcdata TO lt_bdcdata. * OK-Code übergeben CLEAR ls_bdcdata. ls_bdcdata-fnam = 'BDC_OKCODE'. ls_bdcdata-fval = '=WB_DISPLAY'. APPEND ls_bdcdata TO lt_bdcdata. * Transaktion ausführen CALL TRANSACTION 'SFP' USING lt_bdcdata MODE 'E' "E = Stoppen nur bei Error, A = Anzeige (für Test) MESSAGES INTO lt_itab_msg. "Fehlertabelle 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 *&---------------------------------------------------------------------* * Lesen Daten aus Tabelle TNAPR *----------------------------------------------------------------------* FORM GET_DATA CHANGING PCT_ITAB type tty_itab. Select kschl "Nachrichtenart nacha "Medium kappl "Applikation pgnam "Programmname ronam "Form-Routine fonam "SAPScript sform "Smart Forms/Adobe Forms formtype "Typ 1 (Smart Forms), 2 (Adobe Forms) into table pct_itab from tnapr where kschl in s_kschl. ENDFORM.