eventsabapalv

Standard toolbar disappears after applying custom one


I have a ALV grid in a modal dialog that looks as following:

enter image description here

I tried to add tool bar to the ALV as following:

The event class :

CLASS lcl_evt_task_user_cmd IMPLEMENTATION.
  METHOD handle_toolbar.
    e_object->mt_toolbar = VALUE ttb_button(
                           ( butn_type = 3 )
                           ( function = 'EDIT' icon = icon_edit_file butn_type = 0 )
                           ).
  ENDMETHOD.
  METHOD handle_user_command.
    CASE e_ucomm.
      WHEN 'EDIT'.
    ENDCASE.
*    cl_gui_cfw=>set_new_ok_code('DUMMY').
  ENDMETHOD.
ENDCLASS. 

and the way how I register the toolbar:

METHOD show.
    FIELD-SYMBOLS <lt_table> TYPE STANDARD TABLE.
    IF c_go_provider->c_go_grid IS INITIAL.
      DATA(lt_fieldcat) = me->get_fieldcat( c_go_provider->c_gv_struname ).
      c_go_provider->c_go_container = NEW cl_gui_custom_container( container_name = co_grid_name ).
      c_go_provider->c_go_grid = NEW cl_gui_alv_grid( i_parent = c_go_provider->c_go_container ).
      ASSIGN c_go_provider->c_gt_data->* TO <lt_table>.
      me->register_event( ).
      c_go_provider->c_go_grid->set_table_for_first_display(
       EXPORTING
          is_variant = VALUE disvariant( report = sy-repid )
          i_save = 'A'
          is_layout = VALUE lvc_s_layo( sel_mode = 'A' )
        CHANGING
          it_outtab = <lt_table>
          it_fieldcatalog = lt_fieldcat
       ).
      c_go_provider->c_go_grid->set_toolbar_interactive( ).
    ENDIF.
    c_go_provider->c_go_grid->refresh_table_display( ).
  ENDMETHOD.
  METHOD register_event.
    me->c_go_event = NEW lcl_evt_task_user_cmd( ).
    SET HANDLER  me->c_go_event->handle_toolbar
                 me->c_go_event->handle_user_command
        FOR  c_go_provider->c_go_grid.
  ENDMETHOD.

After then, the standard toolbar disappeared:

enter image description here

What am I doing wrong?


Solution

  • You have used value operator with internal table.It first delete the existing contents of internal table and then add the new contents.This is the reason existing toolbar items are not displayed. I have following two solutions to fix the problem.

    Solution 1:

    Replace your following code.

       e_object->mt_toolbar = VALUE ttb_button(
                               ( butn_type = 3 )
                               ( function = 'EDIT' icon = icon_edit_file butn_type = 0 )
                               ).
    

    With the below code,New Toolbar item will be added to toolbar.This will help you to update logic according to your requirement.

    DATA: l_toolbar LIKE LINE OF e_object->mt_toolbar.
    
      l_toolbar-function   = 'EDIT'.
      l_toolbar-icon       = icon_edit_file.
      l_toolbar-quickinfo  = 'Custom Edit'.
      l_toolbar-disabled   = space.
      l_toolbar-butn_type = 0.
    
      APPEND l_toolbar TO e_object->mt_toolbar.
    

    You can also update your existing code with addition of BASE in Value key word.

    Solution 2:

    You can use same value operator with addition of BASE. When you use BASE with VALUE operator, It keep existing contents and add new contents from right side of operator.

    Following is ABAP code using **VALUE operator with Addition of BASE .Toolbar items will not be deleted.**

    e_object->mt_toolbar = VALUE ttb_button( BASE e_object->mt_toolbar
                           ( function = 'EDIT' icon = icon_edit_file butn_type = 0 )
                           ).