Skip to Content
author's profile photo Former Member
Former Member

How can I trigger a USER_COMMAND for alv grid "toolbar" ???

Hi,

i have the standard ALV Grid "toolbar" and if i click to the Button "&LOCAL&COPY_ROW" than i want try to make a Refresh to my ALV Table in the Event "afteruser_command"_!!!!

Here is the implementation of my Event *"afteruser_command":*_

METHOD on_after_user_command.

........DATA: ls_stable TYPE lvc_s_stbl.

.....CASE e_ucomm.

.....WHEN '&LOCAL&COPY_ROW'.

........MESSAGE 'LOCAL_COPY_ROW' TYPE 'S' DISPLAY LIKE 'E'.

........ls_stable-row = 'X'.

........ls_stable-col = 'X'.

........CALL METHOD gr_grid_d0100->refresh_table_display

..............EXPORTING

.......................is_stable = ls_stable

..............EXCEPTIONS

.......................finished = 1

.......................OTHERS = 2.

......ENDCASE.

ENDMETHOD.

But it doesnt work.

Is there another function code for the Copy Button????

Thanks

Ersin

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Jul 07, 2010 at 01:35 PM

    Hello Ersin,

    the events "after_user_command", "before_user_command" and "user_command" will not be fired when selecting this command!

    In my opinion, there is no solution, to fire these events, using this alv-function!

    But there is a trick:

    1. Register on the event "toolbar" with an own method:

    ...
          toolbar_own          for event toolbar of cl_gui_alv_grid
                                       importing e_object
                                              e_interactive,
         ...

    In this method change the function code of "&LOCAL&COPY_ROW", but don´t change the row of the entry, because the button should appear on the same place in the toolbar:

    ...
        field-symbols: <ls_toolbar>  type stb_button.
        read table e_object->mt_toolbar with key function = '&LOCAL&COPY_ROW'
                                        assigning <ls_toolbar>.
        if sy-subrc = 0.
          <ls_toolbar>-function = 'COPYROW_OWN'.
        endif.
         ...

    2. Register on the event "user_command" ( I think, that´s clear ):

    ...
          user_cmd_own           for event user_command
                                              of cl_gui_alv_grid
                                              importing e_ucomm,
         ...

    ( don´t forget the set handler-commands for both events:

    set handler po_alv_own->user_cmd_own for po_alv_own.

    set handler po_alv_own->toolbar_own for po_alv_own. )

    3. Now you can react in the method "user_command" on your own function code:

    ...
        case e_ucomm.
          when 'COPYROW_OWN'.
            perform copy_row using    me
                             changing gt_bis_cf_out.
         ...

    Sample code for copying the current line:

    FORM COPY_ROW  using    po_alv_own          type ref to gcl_alv_own
                   changing pt_table_alv      type gt_table_alv_t.
    
      data: l_index         type i,
            ls_table_alv   type gs_table_alvt_t.
    
    
      call method po_alv_own->get_current_cell
         importing
           e_row     = l_index.
    *      e_value   =
    *      e_col     =
    *      es_row_id =
    *      es_col_id =
    *      es_row_no =
    
      "read the current line:
      read table pt_table_alv index l_index
                               into ls_table_alv_out.
      "some changes for the new row:
      clear: ls_table_alv-style,
             ls_table_alv-tabix.
    
      "insert the new line:
      add 1 to l_index.
      insert ls_table_alv into pt_table_alv index l_index.
    
      po_alv_own->refresh( ).
    
    ENDFORM.                    " COPY_ROW

    In this manner the events "after_user_command", "before_user_command" are fired, too!

    For information: My problem was, that the ALV-function copied the style-information too, so in the new line, some fields are not editable. At least his field must be cleared!

    Best regard

    Thomas Scheuermann

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 23, 2010 at 11:40 AM

    Hi,

    have u checked in debug wat e_ucomm u r getting ? the ucomm which u get is ' %_GC 209 18' check with this ...

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      i can´t check the e_ucomm in the debug Modus, because if i click to this local Button than the Events "User_command" and "After_user_command" dont be called.

      Which Event can be triggered from the Local function codes (e.g. ' &LOCAL&APPEND ')????

      If i overwrite the function code with the toolbar Event to 'LOCAPPEND', than i can trigger the e_ucomm in the "User_command" and "after_user_command".

      What is the reason, that local function codes can´t be triggered from Events????

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.