Move Cursor to next Row by Pressing Enter in OO ALV

By | September 8, 2008 | OO ALV, Uncategorized | 7,212 | 4

I was wondering if it is possible to have the same functionality of the Excel: Press Enter and cursor will move to next row.

As OO ABAP using the class CL_GUI_ALV_GRID provides so many methods for the processing at the Cell Levels. After looking to all the methods of the CL_GUI_ALV_GRID, I found there are so many methods which can do the processing at the Cell level. I have started to give the try. After certain tries, I was able to achieve what I was looking for.

Code Snippet for the Class handler for ALV Grid Call

*& This code snippet sets the handler of the evnets for the OO ALV
*    Data Declaration
     DATAg_grid           type ref to cl_gui_alv_grid,
           g_event_receiver type ref to lcl_event_receiver.

*   Registering the Edit event
    CALL METHOD g_grid->register_edit_event
        i_event_id cl_gui_alv_grid=>mc_evt_enter.
*   Event Handler
    create object g_event_receiver.
*   Event listner method for Edit Event
    SET HANDLER g_event_receiver->handle_data_changed FOR g_grid.
*   calling the instance of the ALV
    call method g_grid->set_table_for_first_display
       changing  it_fieldcatalog       gt_fieldcat
                 it_outtab             gt_outtab[].

Code Snippet for the Class handler definition and Implementation

*& This code snippet shows the Event Handler Class's Definition
*& and implementation
*    Definition
class lcl_event_receiver definition.

  public section.
      handle_data_changed  FOR EVENT data_changed
                           OF cl_gui_alv_grid
                           IMPORTING er_data_changed.


* Class Implementation
class lcl_event_receiver implementation.
  method  handle_data_changed.
*   Local data
    dataLE_ROW TYPE I,
          LE_VALUE TYPE C,
          LE_COL TYPE I,
*   Getting Current Cell
        E_ROW     le_row
        E_VALUE   le_value
        E_COL     le_col
        ES_ROW_ID les_row_id
        ES_COL_ID les_col_id
        ES_ROW_NO les_row_no.
*   Total number of tables
    describe table  gt_outtab lines sy-index.
*   Getting next row
    les_row_id-INDEX  les_row_id-INDEX  1.
    les_row_no-ROW_ID les_row_no-ROW_ID + 1.
*   Set the Next row
    if les_row_id-index le sy-index.
          IS_ROW_ID    les_row_id
          IS_ROW_NO    les_row_no.

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{271 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 271 articles.

Load comments


  • Anonymous


  • Anonymous

    Great example! You saved me a lot of time. Thanks

  • Anonymous


  • gautam

    Hi Namesh,
    It is good but it will works only after changing the cell contents. cursor will not move if cell data is unchanged. Have U tackled this also.

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.