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: 

Addiing Custom button to ALV Grid Standard tool bar

Former Member
0 Kudos

Hello Gurus,

As i wanted to sdd a new button to my alv standard tool bar. Please help me with the procedure.

Regards,

digvijay

1 ACCEPTED SOLUTION

Former Member

Hi Sharma,

For creating a button on the alv toolbar we have to use Event Handler

Check Below Code:

We Define a local class


CLASS LCL_EVENT DEFINITION .

  PUBLIC SECTION.
    METHODS :TOOLBAR FOR EVENT TOOLBAR OF  CL_GUI_ALV_GRID
                     IMPORTING E_OBJECT,
             USER_COMMAND FOR EVENT USER_COMMAND OF CL_GUI_ALV_GRID
                     IMPORTING E_UCOMM.

ENDCLASS.  


CLASS LCL_EVENT IMPLEMENTATION.

  METHOD TOOLBAR.
    WA_TOOL-FUNCTION = 'ZFC1'.
    WA_TOOL-TEXT     = 'TEST'.
    WA_TOOL-ICON     = '@EA@'.
    APPEND WA_TOOL TO E_OBJECT->MT_TOOLBAR.
  ENDMETHOD.             "DISPLAY

  METHOD USER_COMMAND.
    IF E_UCOMM = 'ZFC1'.
      MESSAGE 'THESE IS TEST EVENT' TYPE 'I'.
    ENDIF.
  ENDMETHOD.                    "USER_COMMAND

ENDCLASS.                    "LCL_EVENT IMPLEMENTATION


CREATE OBJECT OBJ.
SET HANDLER : OBJ->TOOLBAR FOR ALV.

Regards,

Kumar M

6 REPLIES 6

former_member555112
Active Contributor
0 Kudos

Hi,

Please check the example programs for ALV grid under the BCALV set of programs in SE38.

Kindly check the program BCALV_TEST_GRID_TOOLBAR. It has the example as to how to add a button in the toolbar.

Regards,

Ankur Parab

Edited by: Ankur Parab on Jun 7, 2009 9:53 PM

venkat_o
Active Contributor
0 Kudos

<pre>Hello digvijay,

To achieve that,

<span style="color:blue;">First step.</span>

Go to SE41 give program name as SAPLKKBL, status as STANDARD_FULLSCREEN and click on COPY STATUS(ctrl+f6) button in application toolbar. One popup is shown, now give To Program and Status .

It copies standard toolbar to your program.now give program name as your program, status as your program status, click on CHANGE button. Add new button in application toolbar.

<span style="color:blue;">Step two</span>

1.Define internal table for ALV events and build events table like below and pass that table through REUSE_ALV_GRID_DISPLAY or REUSE_ALV_LIST_DISPLAY.

<span style="color:blue;">

wa_events-name = 'PF_STATUS_SET'.

wa_events-form = 'PF_STATUS_SET'.

APPEND wa_events TO it_events.

CLEAR wa_events.

wa_events-name = 'USER_COMMAND'.

wa_events-form = 'USER_COMMAND'.

APPEND wa_events TO it_events.

CLEAR wa_events.

</span>

2. Call back routine for above events should be like below.

<span style="color:blue;">&----


*& Form PF_STATUS_SET

&----


  • text

----


  • -->RT_EXTAB text

----


FORM pf_status_set USING rt_extab TYPE slis_t_extab.

SET PF-STATUS 'ZTEST'.

  • 1. When you set Pf status ZTEST, standard application tools will be removed.

  • 2. Goto SE41 give program 'SAPLKKBL' and status 'STANDARD_FULLSCREEN'.

  • 3. Copy the status from those to ZTEST of our program. Now you will see all standard functions.

ENDFORM. "PF_STATUS_SET

----


  • FORM USER_COMMAND *

----


  • --> R_UCOMM *

  • --> RS_SELFIELD *

----


FORM user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

  • Check function code

CASE r_ucomm.

WHEN 'DISPLAY'. "user presses SAVE

LOOP AT it_output INTO wa_output.

IF wa_output-select EQ 'X'.

  • Process records that have been selected

WRITE wa_output.

ENDIF.

ENDLOOP.

ENDCASE.

ENDFORM. "user_command</span>

3. Check this program to know more about events BCALV_TEST_LIST_EVENTS.

Thanks

Venkat</pre>

Former Member
0 Kudos

Hi,

If you ate using ALV with Fun Mod then you can add so in your PF Status,

If you are using OOPS ALV then check out this wiki writeen by me:

https://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=60654876

Thanks,

Krishna..

Former Member

Hi Sharma,

For creating a button on the alv toolbar we have to use Event Handler

Check Below Code:

We Define a local class


CLASS LCL_EVENT DEFINITION .

  PUBLIC SECTION.
    METHODS :TOOLBAR FOR EVENT TOOLBAR OF  CL_GUI_ALV_GRID
                     IMPORTING E_OBJECT,
             USER_COMMAND FOR EVENT USER_COMMAND OF CL_GUI_ALV_GRID
                     IMPORTING E_UCOMM.

ENDCLASS.  


CLASS LCL_EVENT IMPLEMENTATION.

  METHOD TOOLBAR.
    WA_TOOL-FUNCTION = 'ZFC1'.
    WA_TOOL-TEXT     = 'TEST'.
    WA_TOOL-ICON     = '@EA@'.
    APPEND WA_TOOL TO E_OBJECT->MT_TOOLBAR.
  ENDMETHOD.             "DISPLAY

  METHOD USER_COMMAND.
    IF E_UCOMM = 'ZFC1'.
      MESSAGE 'THESE IS TEST EVENT' TYPE 'I'.
    ENDIF.
  ENDMETHOD.                    "USER_COMMAND

ENDCLASS.                    "LCL_EVENT IMPLEMENTATION


CREATE OBJECT OBJ.
SET HANDLER : OBJ->TOOLBAR FOR ALV.

Regards,

Kumar M

0 Kudos

Remember also to set the event handler for USER_COMMAND method in order to be able to use E_UCOMM values.

CREATE OBJECT go_alv.
  SET HANDLER : go_event_handler->TOOLBAR FOR go_alv.
  SET HANDLER : go_event_handler->USER_COMMAND FOR go_alv.

Regards,

Fran K.

Former Member
0 Kudos

Hi Digvijay,

For this requirement, we've to make use of 'toolbar' event of 'cl_gui_alv_grid' and parameter 'e_object' ref to the class 'cl_alv_event_toolbar_set' and it's attributes 'mt_toolbar'.

Pls see the below codin...

In the Definition part, just declare the method as

METHODS handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object.

In Implementation part, include the logic as

METHOD handle_toolbar.

DATA ls_toolbar TYPE stb_button.

ls_toolbar-function = 'PB1'.

ls_toolbar-icon = icon_create_text.

ls_toolbar-quickinfo = 'display selected row'.

ls_toolbar-butn_type = 0.

ls_toolbar-disabled = 1.

ls_toolbar-text = 'display selected row'.

ls_toolbar-checked = ' '.

APPEND ls_toolbar TO e_object->mt_toolbar.

CLEAR ls_toolbar.

ENDMETHOD.

/ Registering handler

SET HANDLER ob->handle_toolbar FOR vbak_grid.

Hope this helpful to you.