2

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?

3
  • ABAP code e_object->mt_toolbar = VALUE ttb_button( ( butn_type = 3 ) ( function = 'EDIT' icon = icon_edit_file butn_type = 0 ) ). is not correct. Jan 9, 2019 at 5:38
  • Value keyword is removing exiting toolbar items and then inserting new item.If you do not want to removing existing items from toolbar then you have to use base with value keyword. Jan 9, 2019 at 6:16
  • Question also asked in SCN: answers.sap.com/questions/722700/… Jan 9, 2019 at 9:53

1 Answer 1

4

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 )
                       ).
2
  • we can deduce the solution only by reading your code, you should better tell the reason of the problem explicitly, for instance : the whole tool bar (i.e. all buttons) is transmitted to the event TOOLBAR, so if you just want to add one button, you must not replace the whole tool bar with your button, but instead, append the button. Jan 9, 2019 at 9:20
  • 2
    @SandraRossi: I have updated the answer with explanation also. Jan 9, 2019 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.