ALV-Vorlage CL GUI ALV GRID
Aus SAP-Wiki
Zur Navigation springenZur Suche springen
Siehe Reporting.
Siehe Report-Vorlage mit Form-Routinen.
Siehe Report-Vorlage mit Lokaler Klasse.
Siehe ALV-Vorlage CL GUI ALV GRID.
Siehe ALV-Vorlage REUSE ALV GRID DISPLAY LVC.
Siehe ALV-Vorlage CL SALV* (Factory).
Siehe Vorlage Upload/Download Datei Frontend.
Siehe Vorlage Upload CSV-Datei mit Job-Steps und Suche nach Stichwort in Programmen.
Siehe Kategorie: ABAP-Vorlagen.
Siehe Kategorie: ALV.
"Kommentarkopf
*&---------------------------------------------------------------------* *& Report Z *& *&---------------------------------------------------------------------* *& Autor: René Eberstein *& Ansprechpartner: *& Erstellungsdatum: *& Modul: *& Beschreibung = *& *&---------------------------------------------------------------------*
"Ein Dynpro 2000 anlegen mit einem Container 'ALV_CONT'
"PROCESS BEFORE OUTPUT. " MODULE STATUS_2000. " MODULE PBO_2000. "PROCESS AFTER INPUT. " MODULE USER_COMMAND_2000.
"Data & Types
**************** * DATA & TYPES * **************** data: go_cont type ref to cl_gui_custom_container, "Def Container-Refobjekt Control (Frontend) go_dock type ref to cl_gui_docking_container,"Def Container-Refobjekt Dock (Hintergrund) go_alv_cont type ref to cl_gui_alv_grid. "Def ALV-Referenzobjekt Types: begin of ty_itab, kunnr type kna1-kunnr, 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. Constants: gv_handle_num1 type SLIS_HANDL value 'NUM1'.
"Selektionsbildschirm
************** * PARAMETERS * ************** SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. PARAMETER: p_vkorg TYPE vkorg. SELECTION-SCREEN END OF BLOCK b1.
Parameter: p_vari TYPE disvariant-variant.
"INITIALIZATION
****************** * INITIALIZATION * ****************** INITIALIZATION. PERFORM initialization.
"AT SELECTION-SCREEN
*********************** * AT SELECTION-SCREEN * *********************** at selection-screen.
"AT SELECTION-SCREEN ON VALUE-REQUEST FOR <FIELD>
*----------------------------------------------------------------------* * AT SELECTION-SCREEN ON VALUE-REQUEST FOR <field> *----------------------------------------------------------------------* AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari. PERFORM at_selection_screen_for_vari CHANGING p_vari.
"START-OF-SELECTION
********************** * START-OF-SELECTION * ********************** start-of-selection.
* Selektion Daten perform get_data changing gt_itab. * Aufruf des Dynpros mit ALV-Container call screen 2000.
"EVENT_handle DEFINITION
*---------------------------------------------------------------------* * CLASS *---------------------------------------------------------------------* CLASS event_handle DEFINITION. PUBLIC SECTION. CLASS-METHODS: handle_double_click FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row "Zeile e_column, "Spalte "#EC NEEDED
handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid IMPORTING e_row_id "Zeile e_column_id, "Spalte
handle_data_changed for event data_changed of cl_gui_alv_grid importing er_data_changed,
handle_toolbar "#EC NEEDED FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object e_interactive, "#EC NEEDED
handle_user_command FOR EVENT user_command OF cl_gui_alv_grid IMPORTING e_ucomm, "sy-ucomm
handle_menu_button FOR EVENT menu_button OF cl_gui_alv_grid IMPORTING e_object e_ucomm. "#EC NEEDED ENDCLASS. "event_handle DEFINITION
"EVENT_HANDLE IMPLEMENTATION
*----------------------------------------------------------------------* * CLASS event_handle IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS event_handle IMPLEMENTATION. METHOD handle_double_click. PERFORM handle_double_click using e_row "Zeile e_column. "Spalte ENDMETHOD. "handle_double_click
METHOD handle_hotspot_click. PERFORM handle_hotspot_click USING e_row_id "Zeile e_column_id. "Spalte ENDMETHOD. "handle_hotspot_click
METHOD handle_data_changed. DATA: ls_good TYPE lvc_s_modi. FIELD-SYMBOLS: <fs_itab> TYPE ty_itab. * Tabelle der modifizierten Zellen abarbeiten LOOP AT er_data_changed->mt_mod_cells INTO ls_good. READ TABLE gt_itab ASSIGNING <fs_itab> INDEX ls_good-row_id. CASE ls_good-fieldname. WHEN 'PDF1'. "<fs_alv>-pdf1 = ls_good-value. ENDCASE. ENDLOOP. ENDMETHOD. "handle_data_changed
METHOD handle_toolbar. PERFORM handle_toolbar CHANGING e_object e_interactive. ENDMETHOD. "handle_toolbar
METHOD handle_menu_button. PERFORM handle_menu_button USING e_object e_ucomm. ENDMETHOD. "handle_menu_button
METHOD handle_user_command. PERFORM handle_user_command using e_ucomm. "sy-ucomm ENDMETHOD. "handle_user_command ENDCLASS. "event_receiver1 IMPLEMENTATION
"Dynpro 2000
module status_2000 output. set pf-status 'STATUS'. "set TITLEBAR 'TITLETEXT'. endmodule.
module pbo_2000 output. perform alv_2000 changing gt_itab. endmodule.
module user_command_2000 input. perform user_command_2000. endmodule.
"Form-Routinen
"Form INITIALIZATION
*&---------------------------------------------------------------------* *& Form INITIALIZATION *&---------------------------------------------------------------------* * Default Routinen *----------------------------------------------------------------------* FORM initialization. DATA: lv_report TYPE rsvar-report, lv_variant TYPE rsvar-variant, ls_variant TYPE disvariant. * Variante STANDARD wird automatisch gezogen lv_report = sy-repid. lv_variant = 'STANDARD'. CALL FUNCTION 'RS_SUPPORT_SELECTIONS' EXPORTING report = lv_report variant = lv_variant EXCEPTIONS variant_not_existent = 1 variant_obsolete = 2 OTHERS = 3. IF sy-subrc <> 0. * Variante & ist nicht vorhanden MESSAGE i809(00) WITH lv_variant. ENDIF. * Defaultlayoutvariante ls_variant-report = sy-repid. ls_variant-handle = gv_handle_num1. CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET' "aus Tabelle LTDX EXPORTING i_save = 'A' CHANGING cs_variant = ls_variant EXCEPTIONS not_found = 2. IF sy-subrc = 0. p_vari = ls_variant-variant. ENDIF. ENDFORM. "INITIALIZATION
"Form AT_SELECTION_SCREEN_FOR_VARI
*&---------------------------------------------------------------------* *& Form AT_SELECTION_SCREEN_FOR_VARI *&---------------------------------------------------------------------* * Liste aller Layoutvarianten wird angeboten und gewählt * Die Selektionsvarianten sind in der Tabelle LTDX gespeichrt *----------------------------------------------------------------------* FORM at_selection_screen_for_vari CHANGING cv_vari TYPE disvariant-variant. DATA: ls_variant_in TYPE disvariant, ls_variant_out TYPE disvariant, lv_exit TYPE c. ls_variant_in-report = sy-repid. ls_variant_in-handle = gv_handle_num1. * Zeigt Liste aller Layoutvarianten an: Benutzervarianten und Standardvarianten CALL FUNCTION 'REUSE_ALV_VARIANT_F4' EXPORTING is_variant = ls_variant_in i_save = 'A' "Benutzer und Standardlayoutvarianten IMPORTING e_exit = lv_exit es_variant = ls_variant_out EXCEPTIONS not_found = 2. IF sy-subrc = 2. MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ELSE. IF lv_exit = space. cv_vari = ls_variant_out-variant. ENDIF. ENDIF. ENDFORM. " AT_SELECTION_SCREEN_FOR_VARI
"Form GET_DATA
*&---------------------------------------------------------------------* *& Form get_data *&---------------------------------------------------------------------* * Selektion Daten *----------------------------------------------------------------------* form get_data changing ct_itab type tty_itab. if sy-subrc <> 0. MESSAGE i550(fre). "Keine Datensätze gefunden leave list-processing. endif. endform.
"Form USER_COMMAND_2000
*&---------------------------------------------------------------------* *& Form user_command_2000 *&---------------------------------------------------------------------* * User-command *----------------------------------------------------------------------* form user_command_2000. CASE sy-ucomm. WHEN 'BACK' OR 'CANCEL' OR 'EXIT'. LEAVE TO SCREEN 0. ENDCASE. endform.
"Form ALV_2000
*&---------------------------------------------------------------------* *& Form alv_2000 *&---------------------------------------------------------------------* * ALV-Output *----------------------------------------------------------------------* form alv_2000 changing ct_itab type tty_itab. type-pools: slis. data: lt_fcat type LVC_T_FCAT, ls_layout type LVC_S_LAYO, * ls_sort type LVC_S_SORT, * lt_sort type LVC_T_SORT ls_variant type DISVARIANT ls_print type lvc_s_print. **************** * Fill Variant * **************** ls_variant-report = sy-repid. ls_variant-handle = gv_handle_num1. ls_variant-variant = p_vari. *************** * Fill Layout * *************** * http://help.sap.com/saphelp_dimp50/helpdata/de/ef/a2e9eff88311d2b48d006094192fe3/content.htm * ls_layout-zebra = 'X'. "Liste wird im Zebra-Look ausgegeben * ls_layout-TOTALS_BEF = 'X'. "Summen vor Einzelsätzen LS_LAYOUT-CWIDTH_OPT = 'A'. "Spaltenbreite wird optimiert (hier ein 'A', nicht 'X' !!) ls_layout-sel_mode = 'D'. "'D' = mit Markierspalte, 'B' = ohne Markierspalte ************* * 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 Fieldcat * ***************** perform alv_fcat "Definition Felder, die ausgegeben werden sollen changing lt_fcat. ********************************* * Container und ALV erzeugen * ********************************* if cl_gui_alv_grid=>offline( ) is initial. " Programm läuft in der Sapgui if go_cont is not bound. CREATE OBJECT go_cont EXPORTING container_name = 'ALV_CONT'. * ALV erzeugen CREATE OBJECT go_alv_cont EXPORTING i_parent = go_cont. endif. else. "Programm läuft im Hintergrund CREATE OBJECT go_alv_cont EXPORTING i_parent = go_dock. * Ausdruck anstoßen. Eventuell müssen die Druckparameter des Users dafür mit * GET_PRINT_PARAMETERS gelesen und mit SET_PRINT_PARAMETERS geändert werden. * Z.B. keine sofortige Ausgabe, Druckerauswahl,... ls_print-print = 'X'. endif. **************************************** * Methode: set_table_for_first_display * **************************************** * Rufe die ALV-Liste auf CALL METHOD go_alv_cont->set_table_for_first_display EXPORTING i_bypassing_buffer = 'X' "lv_bypassing_buffer i_save = 'A' "lv_save * i_default = 'X' is_layout = ls_layout * it_toolbar_excluding = lt_toolbar_excluding is_variant = ls_variant CHANGING it_outtab = ct_itab it_fieldcatalog = lt_fcat. if sy-subrc = 0. go_alv_cont->set_gridtitle( i_gridtitle = 'Liste Verträge'(001) ). "Titelbeschriftung in der ALV-Liste endif. * Register events call method go_alv_cont->register_edit_event exporting i_event_id = cl_gui_alv_grid=>mc_evt_enter. call method go_alv_cont->register_edit_event exporting i_event_id = cl_gui_alv_grid=>mc_evt_modified. * Die Eventhandler werden scharf geschaltet SET HANDLER event_handle=>handle_double_click FOR go_alv_cont. SET HANDLER event_handle=>handle_hotspot_click FOR go_alv_cont. set handler event_handle=>handle_data_changed for go_alv_cont. SET HANDLER event_handle=>handle_toolbar FOR go_alv_cont. SET HANDLER event_handle=>handle_menu_button FOR go_alv_cont. SET HANDLER event_handle=>handle_user_command FOR go_alv_cont. * Die Toolbar soll ergänzt werden um eigene Buttons CALL METHOD go_alv_cont->set_toolbar_interactive. else. PERFORM refresh_alv1. endif. endform.
"Form alv_fcat
*&---------------------------------------------------------------------* *& Form alv_fcat *&---------------------------------------------------------------------* * Feldliste der ALV-Tabelle *----------------------------------------------------------------------* form alv_fcat changing ct_fcat type LVC_T_FCAT. data: ls_fcat type LVC_S_FCAT. * Field = ls_fcat-fieldname = 'KUNNR'. "Feldname interne Tabelle ls_fcat-ref_field = 'KUNNR'. "Feldname typisierendes Feld ls_fcat-ref_table = 'KNA1'. "Tabellenname typisierte Tabelle ls_fcat-key = 'X'. "Spalte ist Key-Spalte (blau und fix beim Scrollen) append ls_fcat to ct_fcat. clear ls_fcat. ** Field = Original Language *ls_fcat-fieldname = . "Feldname der internen Tabelle *ls_fcat-ref_field = . "Feldname des referenzierten Feldes Datenbanktabelle *ls_fcat-ref_table = . "Tabellenname der referenzierten Datenbanktabelle *ls_fcat-reptext = . "Überschriftbeschreibung *ls_fcat-seltext = . "Überschriftbeschreibung *ls_fcat-outputlen = 10. "Spaltenbreite *ls_fcat-emphasize = 'C300'. "Spaltenfarbe (C300 = beige) zrebconstants=>cv_color_fcat_gelb *ls_fcat-edit = 'X'. "Spalte ist eingabefähig *ls_fcat-tooltip = 'Kundenauftrag VBAK-VBELN‘. "Tooltip/Popup bei der Spaltenüberschrift *APPEND ls_fcat TO ct_fcat. *CLEAR ls_fcat. endform. " alv_fcat
"Form REFRESH_ALV
*&---------------------------------------------------------------------* *& Form REFRESH_ALV *&---------------------------------------------------------------------* * Aktualisieren ALV-Liste *----------------------------------------------------------------------* FORM refresh_alv1. DATA: ls_stable TYPE lvc_s_stbl. ls_stable-row = true. ls_stable-col = true. CALL METHOD go_alv_cont->refresh_table_display EXPORTING is_stable = ls_stable EXCEPTIONS finished = 1 OTHERS = 2. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. ENDFORM. " REFRESH_ALV
"Methode GET_SELECTED_ROWS
form get_selected_rows. Data: gt_row_no type lvc_t_roid. call method go_alv_cont->get_selected_rows importing et_row_no = gt_row_no. endform.
"Methode / SET_SELECTED_ROWS
form set_selected_rows. Data: gt_row_no type lvc_t_roid. call method go_alv_cont->set_selected_rows exporting it_row_no = gt_row_no is_keep_other_selections = space. endform.
Splitting Container
Web-Links
- SAP-Hilfe: Methoden der Klasse CL_GUI_ALV_GRID
- SAP-Hilfe: Ereignisse der Klasse CL_GUI_ALV_GRID
- SAP-Hilfe: Layout der Klasse CL_GUI_ALV_GRID
- Tricktresor Fundstellenliste GL_GUI_ALV_GRID
Literatur
- SAP List Viewer (ALV): A Practical Guide for ABAP Developers, von Kathi Kones (EN)
- Praxisworkshop SAP-Controls und SAP List Viewer, von Harald Röser