Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Report Z_BC_ALV_TEMPLATE_001
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT z_bc_alv_template_001.
TYPE-POOLS: icon,slis.
* Tabellen der Varianten
* ltdx
* Ltdxd
* Ltdxs
CONSTANTS ht(1) VALUE %_horizontal_tab.
CONSTANTS c_alv_structure TYPE dd02l-tabname VALUE 'SBOOK'.
TYPES: BEGIN OF ty_data,
xfeld TYPE xfeld.
INCLUDE TYPE sbook.
TYPES: END OF ty_data.
DATA it_data TYPE TABLE OF ty_data.
FIELD-SYMBOLS <p> TYPE ty_data.
*DATA filter TYPE lvc_t_filt WITH HEADER LINE.
* Grid Parameter
DATA: ok_code LIKE sy-ucomm,
g_container TYPE scrfname VALUE 'GRID1',
grid1 TYPE REF TO cl_gui_alv_grid,
g_custom_container TYPE REF TO cl_gui_custom_container,
g_dock_container TYPE REF TO cl_gui_docking_container,
is_variant TYPE disvariant.
*--- Field catalog table
DATA gt_fieldcat TYPE lvc_t_fcat WITH HEADER LINE.
*--- Layout structure
DATA gs_layout TYPE lvc_s_layo .
* LT_EXCLUDE => Tabelle zum Ausschliessen von Funktionen innerhalb
* der Toolbar des ALV-Grid
DATA: lt_exclude TYPE ui_functions,
ls_exclude TYPE ui_func.
* für autom. Variante DEFAULT laden
DATA:
l_report TYPE raldb_repo,
l_variante TYPE raldb_vari,
BEGIN OF t_info OCCURS 0,
typ(1),
null(1),
line(120),
END OF t_info.
SELECT * FROM sbook INTO CORRESPONDING FIELDS OF TABLE it_data.
CALL SCREEN 100.
EXIT.
INITIALIZATION.
** Load variant sy-uname
l_report = sy-repid.
l_variante = sy-uname.
CALL FUNCTION 'RS_COVERPAGE_SELECTIONS'
EXPORTING
report = l_report
variant = l_variante
TABLES
infotab = t_info
EXCEPTIONS
OTHERS = 3.
*---------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION .
PUBLIC SECTION .
METHODS:
*--To add new functional buttons to the ALV toolbar
handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive ,
*--To implement user commands
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
PRIVATE SECTION.
ENDCLASS. "lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION .
*--Handle Toolbar
METHOD handle_toolbar.
PERFORM handle_toolbar USING e_object e_interactive .
ENDMETHOD . "handle_toolbar
*--Handle User Command
METHOD handle_user_command .
PERFORM handle_user_command USING e_ucomm .
ENDMETHOD. "handle_user_command
ENDCLASS. "lcl_event_handler IMPLEMENTATION
DATA gr_event_handler TYPE REF TO lcl_event_handler .
*---------------------------------------------------------------------*
* MODULE PBO OUTPUT *
*---------------------------------------------------------------------*
MODULE pbo OUTPUT.
IF g_custom_container IS INITIAL.
IF cl_gui_alv_grid=>offline( ) IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING
container_name = g_container.
CREATE OBJECT grid1
EXPORTING
i_parent = g_custom_container.
ELSE.
* Hintergrund
CREATE OBJECT grid1
EXPORTING
i_parent = g_dock_container.
ENDIF.
*--Creating an instance for the event handler
CREATE OBJECT gr_event_handler .
*----Preparing field catalog.
PERFORM prepare_field_catalog TABLES gt_fieldcat[] .
*----Preparing layout structure
PERFORM prepare_layout CHANGING gs_layout .
*----Preparing Disable Toolbar Buttons
PERFORM change_buttons .
is_variant-report = sy-repid.
is_variant-variant = '/DEFAULT'.
CALL METHOD grid1->set_table_for_first_display
EXPORTING
is_variant = is_variant
i_save = 'A'
is_layout = gs_layout
it_toolbar_excluding = lt_exclude
CHANGING
it_outtab = it_data[]
it_fieldcatalog = gt_fieldcat[].
*--Registering handler methods to handle ALV Grid events JG
SET HANDLER gr_event_handler->handle_toolbar FOR grid1.
SET HANDLER gr_event_handler->handle_user_command FOR grid1.
* Switch Toolbar of Grid to interactive
CALL METHOD grid1->set_toolbar_interactive.
* Der GRID1 wird noch refreshed
CALL METHOD grid1->refresh_table_display.
ENDIF.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'AUSW' WITH text-001.
ENDMODULE. "PBO OUTPUT
*---------------------------------------------------------------------*
* MODULE PAI INPUT *
*---------------------------------------------------------------------*
MODULE pai INPUT.
* to react on oi_custom_events:
CALL METHOD cl_gui_cfw=>dispatch.
CASE ok_code.
WHEN 'EXIT'.
PERFORM exit_program.
WHEN OTHERS.
* do nothing
ENDCASE.
CLEAR ok_code.
ENDMODULE. "PAI INPUT
*---------------------------------------------------------------------*
* FORM EXIT_PROGRAM *
*---------------------------------------------------------------------*
FORM exit_program.
* CALL METHOD G_CUSTOM_CONTAINER->FREE.
* CALL METHOD CL_GUI_CFW=>FLUSH.
LEAVE TO SCREEN 0.
ENDFORM. "EXIT_PROGRAM
*&--------------------------------------------------------------------*
*& Form Change_buttons
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM change_buttons .
* Kein Symbol für Drucken / Graphik / Info
ls_exclude = cl_gui_alv_grid=>mc_fc_print_back.
APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_graph.
APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_info.
APPEND ls_exclude TO lt_exclude.
ENDFORM. "Change_buttons
*&--------------------------------------------------------------------*
*& Form prepare_layout
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->PS_LAYOUT text
*---------------------------------------------------------------------*
FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo.
DATA rfctxt TYPE rfcdoc-rfcdoc1.
ps_layout-zebra = 'X' .
*ps_layout-cwidth_opt ='X'.
ps_layout-numc_total = ' '.
ps_layout-no_merging = 'X'.
ps_layout-no_rowmark = ' '.
ps_layout-sel_mode = 'A'.
ENDFORM. "prepare_layout
*&--------------------------------------------------------------------*
*& Form handle_toolbar
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->I_OBJECT text
*---------------------------------------------------------------------*
FORM handle_toolbar USING i_object TYPE REF TO cl_alv_event_toolbar_set
e_interactive .
DATA: ls_toolbar TYPE stb_button.
* Paltzhalter / Seperator
CLEAR ls_toolbar.
MOVE 3 TO ls_toolbar-butn_type.
APPEND ls_toolbar TO i_object->mt_toolbar.
* Button MARKIEREN
CLEAR ls_toolbar.
MOVE 'MARK' TO ls_toolbar-function. "#EC NOTEXT
MOVE icon_checkbox TO ls_toolbar-icon.
MOVE 'TOGGLE Select'(201) TO ls_toolbar-quickinfo.
MOVE ' TOGGLE Select'(201) TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled. "#EC NOTEXT
APPEND ls_toolbar TO i_object->mt_toolbar.
* Button Select ALL
CLEAR ls_toolbar.
MOVE 'SELECTALL' TO ls_toolbar-function. "#EC NOTEXT
MOVE icon_select_all TO ls_toolbar-icon.
MOVE 'Select ALL'(202) TO ls_toolbar-quickinfo.
MOVE ' Select ALL'(202) TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled. "#EC NOTEXT
APPEND ls_toolbar TO i_object->mt_toolbar.
* Button Deselect ALL
CLEAR ls_toolbar.
MOVE 'CLEAR' TO ls_toolbar-function. "#EC NOTEXT
MOVE icon_deselect_all TO ls_toolbar-icon.
MOVE 'RESET Select'(203) TO ls_toolbar-quickinfo.
MOVE ' RESET Select'(203) TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled. "#EC NOTEXT
APPEND ls_toolbar TO i_object->mt_toolbar.
* Separator
CLEAR ls_toolbar.
MOVE 3 TO ls_toolbar-butn_type.
APPEND ls_toolbar TO i_object->mt_toolbar.
* Download selected
CLEAR ls_toolbar.
MOVE 'DOWNLOAD' TO ls_toolbar-function. "#EC NOTEXT
MOVE icon_system_save TO ls_toolbar-icon.
MOVE 'Download Documents'(203) TO ls_toolbar-quickinfo.
MOVE ' Download Documents'(203) TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled. "#EC NOTEXT
APPEND ls_toolbar TO i_object->mt_toolbar.
ENDFORM . "handle_toolbar
*&---------------------------------------------------------------------*
*& Form handle_user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM handle_user_command USING i_ucomm TYPE syucomm .
DATA lt_selected_rows TYPE lvc_t_roid .
DATA ls_selected_row TYPE lvc_s_roid .
DATA lv_name TYPE epsfili-name.
DATA lv_flag(1).
DATA lv_stable TYPE lvc_s_stbl.
DATA i TYPE i.
DATA lv_tit(80).
CASE i_ucomm .
WHEN 'MARK' .
CALL METHOD grid1->get_selected_rows
IMPORTING
et_row_no = lt_selected_rows.
* something sected ?
READ TABLE lt_selected_rows INTO ls_selected_row INDEX 1 .
IF sy-subrc NE 0 .
MESSAGE s000(su) WITH 'Select a row!'(205).
ELSE.
LOOP AT lt_selected_rows INTO ls_selected_row.
IF ls_selected_row-row_id NE 0.
READ TABLE it_data ASSIGNING <p> INDEX ls_selected_row-row_id.
IF <p>-xfeld = 'X'.
<p>-xfeld = space.
ELSE.
<p>-xfeld = 'X'.
ENDIF.
lv_flag = <p>-xfeld.
ENDIF.
ENDLOOP.
ENDIF .
* clear all
WHEN 'CLEAR' .
LOOP AT it_data ASSIGNING <p>.
<p>-xfeld = space.
ENDLOOP.
* select All
WHEN 'SELECTALL' .
LOOP AT it_data ASSIGNING <p>.
<p>-xfeld = 'X'.
ENDLOOP.
*Example
WHEN 'DOWNLOAD'.
ENDCASE .
* count selected
CLEAR i.
LOOP AT it_data ASSIGNING <p> WHERE NOT xfeld IS INITIAL.
i = i + 1.
ENDLOOP.
WRITE i TO lv_tit.
CONDENSE lv_tit NO-GAPS.
CONCATENATE text-001 '/' lv_tit 'selected' INTO lv_tit SEPARATED BY space.
SET TITLEBAR 'AUSW' WITH lv_tit.
lv_stable-row = 'X'.
CALL METHOD grid1->refresh_table_display
EXPORTING
is_stable = lv_stable
EXCEPTIONS
finished = 1
OTHERS = 2.
ENDFORM. "handle_user_command
*&--------------------------------------------------------------------*
*& Form prepare_field_catalog
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->PT_FIELDCATtext
*---------------------------------------------------------------------*
FORM prepare_field_catalog TABLES pt_fieldcat TYPE lvc_t_fcat .
DATA ls_fcat TYPE lvc_s_fcat .
FIELD-SYMBOLS <p> TYPE lvc_s_fcat .
DATA ls_dd04l TYPE dd04l.
DATA ls_dd04t TYPE dd04t.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = c_alv_structure
CHANGING
ct_fieldcat = pt_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
*--Exception handling
ENDIF.
CLEAR ls_fcat.
SELECT SINGLE * FROM dd04l INTO CORRESPONDING FIELDS OF ls_fcat WHERE
rollname = 'MARKE' AND
as4local = 'A' AND
as4vers = ' '.
SELECT SINGLE * FROM dd04t INTO CORRESPONDING FIELDS OF ls_fcat WHERE
rollname = 'MARKE' AND
ddlanguage = sy-langu AND
as4local = 'A' AND
as4vers = ' '.
ls_fcat-fieldname = 'XFELD'.
ls_fcat-checkbox = 'X'.
* ls_fcat-domname = 'FLAG'.
* ls_fcat-dd_outlen = '1'.
* ls_fcat-intlen = '1'.
* ls_fcat-coltext = 'Select'.
* ls_fcat-reptext = 'Select'.
* ls_fcat-scrtext_l = 'Select'.
* ls_fcat-scrtext_m = 'Select'.
* ls_fcat-scrtext_s = 'Select'.
* ls_fcat-ref_table = 'KAEP_COAC'.
* ls_fcat-tabname = '1'.
INSERT ls_fcat INTO pt_fieldcat INDEX 1.
* Assign correct order number
LOOP AT pt_fieldcat ASSIGNING <p>.
<p>-col_pos = sy-tabix.
ENDLOOP.
ENDFORM . "prepare_field_catalog
Folgende Benutzer bedankten sich beim Autor Tron für den Beitrag:
kolumbus70