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: 

add new buttons to the alv toolbar

Former Member
0 Kudos
2,361

how can i add new buttons on the toolbar? i can exclude button from the standard but how can i add some?

15 REPLIES 15

Former Member
0 Kudos
147

Hi,

Check this example program in your R3 system: BCALV_TEST_GRID_TOOLBAR

regards,

Advait

Former Member
0 Kudos
147

CLASS LCL_EVENT_HANDLER DEFINITION.

PUBLIC SECTION.

METHODS : HANDLE_TOOLBAR FOR EVENT TOOLBAR OF CL_GUI_ALV_GRID

IMPORTING E_OBJECT E_INTERACTIVE.

ENDCLASS. "lcl_event_handler DEFINITION

CLASS LCL_EVENT_HANDLER IMPLEMENTATION.

METHOD HANDLE_TOOLBAR.

DATA: WA_TOOLBAR TYPE STB_BUTTON.

CLEAR WA_TOOLBAR.

MOVE 'EDIT' TO WA_TOOLBAR-FUNCTION.

MOVE ICON_SYSTEM_COPY TO WA_TOOLBAR-ICON.

MOVE 'Sets Grid in Edit Mode' TO WA_TOOLBAR-QUICKINFO.

MOVE 'Edit' TO WA_TOOLBAR-TEXT.

MOVE ' ' TO WA_TOOLBAR-DISABLED.

APPEND WA_TOOLBAR TO E_OBJECT->MT_TOOLBAR.

CLEAR WA_TOOLBAR.

MOVE 'UPDATE' TO WA_TOOLBAR-FUNCTION.

MOVE ICON_SYSTEM_SAVE TO WA_TOOLBAR-ICON.

MOVE 'Updates all the changed data' TO WA_TOOLBAR-QUICKINFO.

MOVE 'Update' TO WA_TOOLBAR-TEXT.

MOVE ' ' TO WA_TOOLBAR-DISABLED.

APPEND WA_TOOLBAR TO E_OBJECT->MT_TOOLBAR.

ENDMETHOD. "HANDLE_TOOLBAR

ENDCLASS "lcl_event_handler IMPLEMENTATION

MODULE STATUS_3000 OUTPUT.

..........................

CREATE OBJECT GR_EVENT_HANDLER.

SET HANDLER GR_EVENT_HANDLER->HANDLE_TOOLBAR FOR GR_ALVGRID.

0 Kudos
147

how is the definition for GR_EVENT_HANDLER ?

is there another alternative without a class definition and implementation to create additional button on the toolbar?

0 Kudos
147

DATA GR_EVENT_HANDLER TYPE REF TO LCL_EVENT_HANDLER.

0 Kudos
147

Hi,

1) if u want to add new button to toolbar in standard program, it isn't possible

2) in another case if u want to create button in alv toolbar in your program it's possible for you need copy alv toolbar from standard program and then u can change it (create&delete buttons etc.) . for example u can copy gui-status 'STANDARD' of BALVSD01 program.

0 Kudos
147

how do i define GR_ALVGRID? you use this to call the method.

0 Kudos
147

if it's question for me , i didn't understand u . what though how u define your reference ? u can only exclude buttons by program but how adding button i explaned u above .

Edited by: Ruslan Burhanov on Nov 19, 2008 1:10 PM

0 Kudos
147

hello,

when I copy the standard tololbar of the mentioned progam, how do i create new buttons for it?

0 Kudos
147

u can add new button for copied toolbar by follow

1) open GUI-status for changing

2) add new item in any position of application toolbar (Edit -> Insert -> Entry)

3) in that item u can your button

thats all

0 Kudos
147

sorry ruslan, i think i didn't explain it enougt, i dont want to have a menue toolbar, what i want to have is the alv grid toolbar which is above the alv and not under the menue.

0 Kudos
147

hi,

just create a status

SET PF-STATUS 'ZTEST'.

click on ztest-->here u can add ur own buttons.

Best Regards,

Venkat

0 Kudos
147

i don't mean the pf-status which is for the whole screen, i mean the toolbar for the alv, which belongs to the alv

CALL METHOD grid1->set_table_for_first_display

EXPORTING

i_structure_name = 'ZRFID'

is_layout = gs_layout

it_toolbar_excluding = lt_exclude

CHANGING

it_outtab = lt_alv

it_fieldcatalog = lt_fct1

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

with my lt_exclude i can remove button, but how can i add buttons?

0 Kudos
147

now i have this one:


*---------------------------------------------------------------------*
*       CLASS LCL_EVENT_HANDLER DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
  PUBLIC SECTION.
    METHODS:
      toolbar              FOR EVENT toolbar
                           OF cl_gui_alv_grid
                           IMPORTING e_object
                                     e_interactive.

ENDCLASS.                                 "lcl_event_handler DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
  METHOD toolbar.
    PERFORM toolbar USING e_object
                          e_interactive.
  ENDMETHOD.                    "toolbar

ENDCLASS. "lcl_event_handler IMPLEMENTATION

***********************************************************************************
FORM toolbar USING e_object TYPE REF TO cl_alv_event_toolbar_set
     e_interactive          TYPE        char1.

  DATA: ls_toolbar TYPE stb_button.


*... Normal Button
  CLEAR ls_toolbar.
  ls_toolbar-function  = 'Toggle'.                          "#EC NOTEXT
  ls_toolbar-icon      = icon_toggle_display_change.
  ls_toolbar-butn_type = '0'.
  ls_toolbar-disabled  = space.
  ls_toolbar-text      = 'Toggle'.                          "#EC NOTEXT
  ls_toolbar-quickinfo = space.
  ls_toolbar-checked   = space.
  APPEND ls_toolbar TO e_object->mt_toolbar.

ENDFORM.                    " toolbar

  CALL METHOD grid1->set_table_for_first_display
    EXPORTING
      i_structure_name              = 'STRUCTURE'
      is_layout                     = gs_layout
      it_toolbar_excluding          = lt_exclude
    CHANGING
      it_outtab                     = lt_alv
      it_fieldcatalog               = lt_fct1
    EXCEPTIONS
      invalid_parameter_combination = 1
      program_error                 = 2
      too_many_lines                = 3
      OTHERS                        = 4.

but i don't have a additional button 'Toggle' in my toolbar.

0 Kudos
147

Hi,

First you need to create an object of the event handler class and then you need to set the handler of the event class method to the grid as well.

Do this before you call the method set_table_for_first_display of the grid


  create object gr_event_handler . 
" you must declare gr_event handler as gr_event_handler type ref to lcl_event_handler

  set handler gr_events_sflight->toolbar
              for grid1.


regards,

Advait

Edited by: Advait Gode on Nov 20, 2008 11:19 AM

0 Kudos
147

Thanks now it works.