Move Cursor to next Row by Pressing Enter in OO ALV

Posted by Krishh Webworld | 6:18 PM | , , | 2 comments »

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

DATA: g_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
EXPORTING
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.
methods:
handle_data_changed FOR EVENT data_changed
OF cl_gui_alv_grid
IMPORTING er_data_changed.

endclass.


* Class Implementation
class lcl_event_receiver implementation.
method handle_data_changed.
*
* Local data
data: LE_ROW TYPE I,
LE_VALUE TYPE C,
LE_COL TYPE I,
LES_ROW_ID TYPE LVC_S_ROW,
LES_COL_ID TYPE LVC_S_COL,
LES_ROW_NO TYPE LVC_S_ROID.
*
* Getting Current Cell
CALL METHOD G_GRID->GET_CURRENT_CELL
IMPORTING
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.
CALL METHOD G_GRID->SET_CURRENT_CELL_VIA_ID
EXPORTING
IS_ROW_ID = les_row_id
IS_COLUMN_ID = LES_COL_ID
IS_ROW_NO = les_row_no.
endif.
endmethod.
endclass.

2 comments

  1. admin // December 4, 2011 at 2:26 PM  
  2. Anonymous // December 26, 2011 at 12:19 PM  

    Beautiful coding....

    Loved it...

    Got my work..

    god bless you!!

    My requirement was to move custom alv cursor to next row on ENTER

Archives

Subscribe Now: Feed Icon