Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

toolbar in ALV grid

Former Member
0 Kudos

hi,

how to create pushbuttons in the toolbar of ALV grid control.

thanks

vijay.

1 ACCEPTED SOLUTION

uwe_schieferstein
Active Contributor
0 Kudos

Hello Vijay

Here is a simple report explaining toolbar handling. The crucial points are:

[code]* Set event handler for event TOOLBAR

SET HANDLER:

lcl_eventhandler=>handle_toolbar FOR grid1.

  • $Comment: Toolbar can be modified on-the-fly

grid1->set_toolbar_interactive( ).[/code]

[code]* Event handler method for event TOOLBAR:

METHOD handle_toolbar.

DATA:

ls_button TYPE stb_button.

ls_button-function = 'NEW_BUTTON'.

ls_button-icon = icon_detail.

ls_button-quickinfo = 'New Button'.

APPEND ls_button TO e_object->mt_toolbar.

ENDMETHOD. "handle_toolbar[/code]

Here is the entire coding:

[code]PROGRAM ZUS_SDN_BCALV_GRID_DEMO_3.

DATA: ok_code LIKE sy-ucomm,

gt_sflight TYPE TABLE OF sflight,

g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',

grid1 TYPE REF TO cl_gui_alv_grid,

g_custom_container TYPE REF TO cl_gui_custom_container.

TYPE-POOLS: icon.

----


  • CLASS lcl_eventhandler DEFINITION

----


*

----


CLASS lcl_eventhandler DEFINITION.

PUBLIC SECTION.

CLASS-DATA:

md_cnt TYPE i.

CLASS-METHODS:

handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING

e_object

e_interactive

sender.

ENDCLASS. "lcl_eventhandler DEFINITION

----


  • CLASS lcl_eventhandler IMPLEMENTATION

----


*

----


CLASS lcl_eventhandler IMPLEMENTATION.

METHOD handle_toolbar.

DATA:

ls_button TYPE stb_button.

ls_button-function = 'NEW_BUTTON'.

ls_button-icon = icon_detail.

ls_button-quickinfo = 'New Button'.

APPEND ls_button TO e_object->mt_toolbar.

ENDMETHOD. "handle_toolbar

ENDCLASS. "lcl_eventhandler IMPLEMENTATION

START-OF-SELECTION.

----


  • MAIN *

----


SELECT * FROM sflight INTO TABLE gt_sflight.

CALL SCREEN 100.

----


  • MODULE PBO OUTPUT *

----


MODULE pbo OUTPUT.

SET PF-STATUS 'MAIN100'.

IF g_custom_container IS INITIAL.

CREATE OBJECT g_custom_container

EXPORTING container_name = g_container.

  • Instantiate ALV grid control

CREATE OBJECT grid1

EXPORTING i_parent = g_custom_container.

CALL METHOD grid1->set_table_for_first_display

EXPORTING

i_structure_name = 'SFLIGHT'

CHANGING

it_outtab = gt_sflight.

  • Set event handler for event TOOLBAR

SET HANDLER:

lcl_eventhandler=>handle_toolbar FOR grid1.

  • $Comment: Toolbar can be modified on-the-fly

grid1->set_toolbar_interactive( ).

ENDIF.

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 PROGRAM.

ENDFORM. "EXIT_PROGRAM[/code]

Regards

Uwe

6 REPLIES 6

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Please check example program BCALV_GRID_05, it will show you exactly what you need to do.

Regards,

RIch Heilman

uwe_schieferstein
Active Contributor
0 Kudos

Hello Vijay

Here is a simple report explaining toolbar handling. The crucial points are:

[code]* Set event handler for event TOOLBAR

SET HANDLER:

lcl_eventhandler=>handle_toolbar FOR grid1.

  • $Comment: Toolbar can be modified on-the-fly

grid1->set_toolbar_interactive( ).[/code]

[code]* Event handler method for event TOOLBAR:

METHOD handle_toolbar.

DATA:

ls_button TYPE stb_button.

ls_button-function = 'NEW_BUTTON'.

ls_button-icon = icon_detail.

ls_button-quickinfo = 'New Button'.

APPEND ls_button TO e_object->mt_toolbar.

ENDMETHOD. "handle_toolbar[/code]

Here is the entire coding:

[code]PROGRAM ZUS_SDN_BCALV_GRID_DEMO_3.

DATA: ok_code LIKE sy-ucomm,

gt_sflight TYPE TABLE OF sflight,

g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',

grid1 TYPE REF TO cl_gui_alv_grid,

g_custom_container TYPE REF TO cl_gui_custom_container.

TYPE-POOLS: icon.

----


  • CLASS lcl_eventhandler DEFINITION

----


*

----


CLASS lcl_eventhandler DEFINITION.

PUBLIC SECTION.

CLASS-DATA:

md_cnt TYPE i.

CLASS-METHODS:

handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING

e_object

e_interactive

sender.

ENDCLASS. "lcl_eventhandler DEFINITION

----


  • CLASS lcl_eventhandler IMPLEMENTATION

----


*

----


CLASS lcl_eventhandler IMPLEMENTATION.

METHOD handle_toolbar.

DATA:

ls_button TYPE stb_button.

ls_button-function = 'NEW_BUTTON'.

ls_button-icon = icon_detail.

ls_button-quickinfo = 'New Button'.

APPEND ls_button TO e_object->mt_toolbar.

ENDMETHOD. "handle_toolbar

ENDCLASS. "lcl_eventhandler IMPLEMENTATION

START-OF-SELECTION.

----


  • MAIN *

----


SELECT * FROM sflight INTO TABLE gt_sflight.

CALL SCREEN 100.

----


  • MODULE PBO OUTPUT *

----


MODULE pbo OUTPUT.

SET PF-STATUS 'MAIN100'.

IF g_custom_container IS INITIAL.

CREATE OBJECT g_custom_container

EXPORTING container_name = g_container.

  • Instantiate ALV grid control

CREATE OBJECT grid1

EXPORTING i_parent = g_custom_container.

CALL METHOD grid1->set_table_for_first_display

EXPORTING

i_structure_name = 'SFLIGHT'

CHANGING

it_outtab = gt_sflight.

  • Set event handler for event TOOLBAR

SET HANDLER:

lcl_eventhandler=>handle_toolbar FOR grid1.

  • $Comment: Toolbar can be modified on-the-fly

grid1->set_toolbar_interactive( ).

ENDIF.

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 PROGRAM.

ENDFORM. "EXIT_PROGRAM[/code]

Regards

Uwe

Former Member
0 Kudos

Hi

try this ...

Declare this in your data declaration part.

CLASS cl_event_receiver DEFINITION DEFERRED.

DATA: cl_event_receiver TYPE REF TO cl_event_receiver.

CLASS cl_event_receiver DEFINITION.

PUBLIC SECTION.

CLASS-METHODS:

handle_toolbar

FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING e_object e_interactive.

ENDCLASS.

CLASS cl_event_receiver IMPLEMENTATION.

  • *Handle toolbar

METHOD handle_toolbar.

DATA: ls_toolbar TYPE stb_button.

CLEAR ls_toolbar.

MOVE 'PRINT' TO ls_toolbar-function.

MOVE '@0X@' TO ls_toolbar-icon.

MOVE 'Print data' TO ls_toolbar-quickinfo.

MOVE ' ' TO ls_toolbar-disabled.

APPEND ls_toolbar TO e_object->mt_toolbar.

ENDMETHOD. "handle_toolbar

  • This code will add an extra print button in the toolbar.

  • For adding button of your choice you have to change in the "MOVE '@0X@' TO ls_toolbar-icon " statement. You can select the symbol for button from the ICONS inlcude .

Create the object of cl_event_receiver class.

CREATE OBJECT cl_event_receiver.

SET HANDLER cl_event_receiver->handle_toolbar FOR g_alv1.

g_alv1 is the name of grid.

Former Member
0 Kudos

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

data : w_toolbar type stb_button,

o_docking type ref to cl_gui_docking_container,"Docking container

o_grid type ref to cl_gui_alv_grid, "ALV Grid

o_event type ref to lcl_event_receiver. "Events

CLASS lcl_event_receiver DEFINITION DEFERRED.

class cl_gui_container definition load.

CLASS lcl_event_receiver DEFINITION.

  • event receiver definitions for ALV actions

PUBLIC SECTION.

METHODS:

  • Tool bar

handle_toolbar

FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING e_object

e_interactive.

ENDCLASS.

CLASS lcl_event_receiver IMPLEMENTATION.

  • create the relevant buttons on the toolbars

METHOD handle_toolbar.

MOVE : 'COUNT' TO w_toolbar-function,

'' TO w_toolbar-icon,

'' TO w_toolbar-quickinfo,

'' TO w_toolbar-butn_type,

'' TO w_toolbar-disabled,

'COUNT' TO w_toolbar-text.

APPEND w_toolbar TO e_object->mt_toolbar.

ENDMETHOD.

ENDCLASS.

In the PBO of the screen,

SET HANDLER o_event->handle_toolbar FOR o_grid.

Using the above coding,you are adding a button named COUNT to the toolbar.

Kindly reward points by clicking the star on the left of reply,if it helps.

Former Member
0 Kudos

hi,

Create a event form for user_command either in the Grid Function module or using event catalog( Check for the events). there u can create u'r own PF Status or copy standard ALV toolbar into u'r own PF Status and add new fuctionality thru menu painter(SE41). Try it!.

If this helps u, plz award points.

regards,

Aravind