eventsevent-handlingabapalv

CALL METHOD and -> behave differently for ALV events. Why?


I hope that i got the title right because i seriously can't think of a short description for this scenario. I'll try to make it brief:

I have an editable ALV which displays some data and whenever the User inputs data and changes the active cell (e.g. clicks on another cell, presses an arrow key,etc.) the event "data_changed" of the ALV grid should be triggered.

Now to my question: When I use the following code

*   ENTER key is pressed
    CALL METHOD go_grid->register_edit_event
      EXPORTING
        i_event_id = cl_gui_alv_grid=>mc_evt_enter.

*   data is changed and cursor is moved from the cell
    CALL METHOD go_grid->register_edit_event
      EXPORTING
        i_event_id = cl_gui_alv_grid=>mc_evt_modified.

The event is triggered as it should be. However when I use:

go_grid->register_edit_event( i_event_id = cl_gui_alv_grid=>mc_evt_enter ).
go_grid->register_edit_event( i_event_id = cl_gui_alv_grid=>mc_evt_enter ).

No event is triggered when i do the same actions. But aren't these 2 ways basically the same or are they functioning differently from each other? Documentation also states that CALL METHOD is obsolete and shouldn't be used anymore.


Solution

  • You read correctly: CALL METHOD foo->bar EXPORTING x = y. and foo->bar( x = y ). do the exact same thing. They are alternative syntax for the same functionality.

    The difference in behavior you encounter might be because you are not actually doing the same thing in both code snippets.

    In the first snippet, you pass mc_evt_enter to the first method call and mc_evt_modified to the second method call. But in the second code snippet, you pass mc_evt_enter to both method calls.

    Try this:

    go_grid->register_edit_event( i_event_id = cl_gui_alv_grid=>mc_evt_enter ).
    go_grid->register_edit_event( i_event_id = cl_gui_alv_grid=>mc_evt_modified ).