*&---------------------------------------------------------------------*
*&Report:ZALV_TOOLBAR *
*&Author : Swarna.S
*&---------------------------------------------------------------------*
*& AS : ALV report with user defined buttons in its toolbar
*& and when clicking the last yellow button(arrow) can display the
*& toolbar and expand it in three steps
*---------------------------------------------------------------------*
REPORT zalv_toolbar.
TYPE-POOLS : slis,icon.
TYPES : BEGIN OF ty_table,
tcode TYPE tcode,
pgmna TYPE progname,
END OF ty_table.
TYPES : BEGIN OF ty_itext,
tcode TYPE tcode,
ttext TYPE ttext_stct,
sprsl TYPE sprsl,
END OF ty_itext.
TYPES : BEGIN OF ty_output,
tcode TYPE tcode,
pgmna TYPE progname,
ttext TYPE ttext_stct,
END OF ty_output.
DATA : it_table TYPE STANDARD TABLE OF ty_table INITIAL SIZE 0,
it_output TYPE STANDARD TABLE OF ty_output INITIAL SIZE 0,
it_ittext TYPE STANDARD TABLE OF ty_itext INITIAL SIZE 0,
wa_table TYPE ty_table,
wa_output TYPE ty_output,
wa_ittext TYPE ty_itext.
CLASS: lcl_alv_toolbar DEFINITION DEFERRED.
DATA : ty_toolbar TYPE stb_button.
DATA: c_ccont TYPE REF TO cl_gui_custom_container, "Custom container object
c_alvgd TYPE REF TO cl_gui_alv_grid, "ALV grid object
it_fcat TYPE lvc_t_fcat, "Field catalogue
it_layout TYPE lvc_s_layo, "Layout
c_alv_toolbar TYPE REF TO lcl_alv_toolbar, "Alv toolbar
c_alv_toolbarmanager TYPE REF TO cl_alv_grid_toolbar_manager. "Toolbar manager
*Initialization event
INITIALIZATION.
START-OF-SELECTION.
PERFORM fetch_data.
PERFORM alv_output.
* CLASS lcl_alv_toolbar DEFINITION
*---------------------------------------------------------------------*
* ALV event handler
*---------------------------------------------------------------------*
PUBLIC SECTION.
*Constructor
METHODS: constructor
IMPORTING
io_alv_grid TYPE REF TO cl_gui_alv_grid,
*Event for toolbar
on_toolbar
FOR EVENT toolbar
OF cl_gui_alv_grid
IMPORTING
e_object.
ENDCLASS. "lcl_alv_toolbar DEFINITION
* CLASS lcl_alv_toolbar IMPLEMENTATION
*---------------------------------------------------------------------*
* ALV event handler
*---------------------------------------------------------------------*
METHOD constructor.
CREATE OBJECT c_alv_toolbarmanager
EXPORTING
io_alv_grid = io_alv_grid.
ENDMETHOD. "constructor
METHOD on_toolbar.
* Add customized toolbar buttons.
* variable for Toolbar Button
ty_toolbar-icon = icon_generate.
ty_toolbar-butn_type = 0.
ty_toolbar-text = 'Button1'.
APPEND ty_toolbar TO e_object->mt_toolbar.
ty_toolbar-icon = icon_voice_output.
ty_toolbar-butn_type = 0.
ty_toolbar-text = 'Button2'.
APPEND ty_toolbar TO e_object->mt_toolbar.
ty_toolbar-icon = icon_phone.
ty_toolbar-butn_type = 0.
ty_toolbar-text = 'Button3'.
APPEND ty_toolbar TO e_object->mt_toolbar.
ty_toolbar-icon = icon_mail.
ty_toolbar-butn_type = 0.
ty_toolbar-text = 'Button4'.
APPEND ty_toolbar TO e_object->mt_toolbar.
ty_toolbar-icon = icon_voice_input.
ty_toolbar-butn_type = 0.
ty_toolbar-text = 'Button5'.
APPEND ty_toolbar TO e_object->mt_toolbar.
** Call reorganize method of toolbar manager to
** display the toolbar
CALL METHOD c_alv_toolbarmanager->reorganize
EXPORTING
io_alv_toolbar = e_object.
ENDMETHOD. "on_toolbar
ENDCLASS. "lcl_alv_toolbar IMPLEMENTATION
*&---------------------------------------------------------------------*
*& Form fetch_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text *----------------------------------------------------------------------*
FOR ALL ENTRIES IN it_table WHERE tcode = it_table-tcode AND sprsl = 'E'. ENDIF.
*Apppending the data to the internal table of ALV output.
LOOP AT it_table INTO wa_table.
wa_output-tcode = wa_table-tcode.
wa_output-pgmna = wa_table-pgmna.
* For texts
READ TABLE it_ittext INTO wa_ittext WITH KEY tcode = wa_table-tcode.
wa_output-ttext = wa_ittext-ttext.
APPEND wa_output TO it_output.
CLEAR wa_output.
ENDLOOP.
ENDFORM. " fetch_data
*&---------------------------------------------------------------------*
*& Form alv_output *&---------------------------------------------------------------------*
* text *----------------------------------------------------------------------* * --> p1 text
ENDFORM. " alv_output
** Calling the ALV screen with custom container
*On this statement double click it takes you to the screen painter SE51.
*Enter the attributes
*Create a Custom container and name it CC_CONT and OK code as OK_CODE.
*Save check and Activate the screen painter.
*Now a normal screen with number 600 is created which holds the ALV grid.
* PBO of the actual screen , Here we can give a title and
*customized menus *&---------------------------------------------------------------------*
*& Module STATUS_0600 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------*
MODULE status_0600 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0600 OUTPUT
* calling the PBO module ALV_GRID. *&---------------------------------------------------------------------* *& Module ALV_GRID OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------
* MODULE alv_grid OUTPUT.
*create object for custom container
CREATE OBJECT c_ccont
EXPORTING
container_name = 'CC_CONT'.
*create object of alv grid
CREATE OBJECT c_alvgd
EXPORTING
i_parent = c_ccont.
* create ALV event handler
CREATE OBJECT c_alv_toolbar
EXPORTING
io_alv_grid = c_alvgd.
* Register event handler
SET HANDLER c_alv_toolbar->on_toolbar FOR c_alvgd.
PERFORM alv_build_fieldcat.
PERFORM alv_report_layout.
CALL METHOD c_alvgd->set_table_for_first_display
EXPORTING
is_layout = it_layout
CHANGING
it_outtab = it_output
it_fieldcatalog = it_fcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDMODULE. " ALV_GRID OUTPUT
*& Form alv_build_fieldcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_IT_FCAT text *----------------------------------------------------------------------* FORM alv_build_fieldcat. DATA lv_fldcat TYPE lvc_s_fcat. CLEAR lv_fldcat.
lv_fldcat-col_pos = '1'.
lv_fldcat-fieldname = 'TCODE'.
lv_fldcat-tabname = 'IT_OUTPUT'.
lv_fldcat-outputlen = 8.
lv_fldcat-scrtext_m = 'TCODE'.
APPEND lv_fldcat TO it_fcat.
CLEAR lv_fldcat.
lv_fldcat-col_pos = '2'.
lv_fldcat-fieldname = 'PGMNA'.
lv_fldcat-tabname = 'IT_OUTPUT'.
lv_fldcat-outputlen = 15.
lv_fldcat-scrtext_m = 'PROGNAME'.
APPEND lv_fldcat TO it_fcat.
CLEAR lv_fldcat.
lv_fldcat-col_pos = '3'.
lv_fldcat-fieldname = 'TTEXT'.
lv_fldcat-tabname = 'IT_OUTPUT'.
lv_fldcat-outputlen = 60.
lv_fldcat-scrtext_m = 'Description'.
APPEND lv_fldcat TO it_fcat.
CLEAR lv_fldcat.
*& Form alv_report_layout
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_IT_LAYOUT text *----------------------------------------------------------------------*
it_layout-cwidth_opt = 'X'.
it_layout-zebra = 'X'.
ENDFORM. " alv_report_layout
*for additional functionalities we can create OK codes
*and based on the user command we can do the coding.
*& Module USER_COMMAND_0600 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
ENDMODULE. " USER_COMMAND_0600 INPUT
ALSO READ:
- ALV Report Program - Colors- Using REUSE_ALV_GRID_DISPLAY_LVC.
- Displaying Percentage In ALV List / Grid Display.
- Handling An ALV Grid With Check Box Using A Method.
- Handling Radio Buttons In ALV Report.
..... Back To Index On ALV List/ Grid Display.
..... Back To MAIN INDEX.
Hi There,
ReplyDeleteI used this code of yours above as an example and I got the button on the ALV toolbar,but how do you handle the clicking of the button that you have added?? Please any help would be appreciated.
Kind Regards
Jacques