Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ALV Grid Get Rows Selected.

Former Member
0 Likes
2,667

Hi Gurus,

I have completed an ALV Grid output which is basically an editable table.

Is there any Event which is triggered after selecting a row or any Event to find the no. of rows selected in the ALV output? (Couldnt find it in cl_gui_alv_grid class? )

Appreciate any inputs..

Thanks,

Venkat

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,427

Hi Venkat ,

Whenever a row is selected in the ALV screen, It is saved in the Final table that is used for the display.

So you can use the Event " handle_data_changed " to capture it

eg:

&----


  • Event Handler Declarations

&----


----


  • CLASS lcl_event_receiver 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. "lcl_event_receiver DEFINITION

----


  • CLASS LCL_EVENT_RECEIVER IMPLEMENTATION

----


CLASS lcl_event_receiver IMPLEMENTATION.

METHOD handle_data_changed.

PERFORM handle_data_changed USING er_data_changed.

ENDMETHOD. "handle_data_changed

ENDCLASS. "lcl_event_receiver IMPLEMENTATION

FORM handle_data_changed USING ir_data_changed

TYPE REF TO cl_alv_changed_data_protocol.

DATA: lwa_mod_cell TYPE lvc_s_modi,

lwa_row_no TYPE lvc_s_roid,

lwa_column_id TYPE lvc_s_col.

LOOP AT ir_data_changed->mt_mod_cells

INTO lwa_mod_cell.

  • clear : ws_set.

CASE lwa_mod_cell-fieldname.

WHEN c_select. ( selected row)

READ TABLE i_final INTO wa_final

INDEX lwa_mod_cell-row_id.

IF sy-subrc = 0.

CLEAR : ws_set.

wa_final-status = lwa_mod_cell-value.

MODIFY i_final FROM wa_final

INDEX lwa_mod_cell-row_id

TRANSPORTING status .

ENDIF.

ENDLOOP.

ENDFORM. " handle_data_changed

Regards,

Chitra.

Hi Gurus,

I have completed an ALV Grid output which is basically an editable table.

Is there any Event which is triggered after selecting a row or any Event to find the no. of rows selected in the ALV output? (Couldnt find it in cl_gui_alv_grid class? )

Appreciate any inputs..

Thanks,

Venkat

5 REPLIES 5
Read only

Former Member
0 Likes
1,428

Hi Venkat ,

Whenever a row is selected in the ALV screen, It is saved in the Final table that is used for the display.

So you can use the Event " handle_data_changed " to capture it

eg:

&----


  • Event Handler Declarations

&----


----


  • CLASS lcl_event_receiver 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. "lcl_event_receiver DEFINITION

----


  • CLASS LCL_EVENT_RECEIVER IMPLEMENTATION

----


CLASS lcl_event_receiver IMPLEMENTATION.

METHOD handle_data_changed.

PERFORM handle_data_changed USING er_data_changed.

ENDMETHOD. "handle_data_changed

ENDCLASS. "lcl_event_receiver IMPLEMENTATION

FORM handle_data_changed USING ir_data_changed

TYPE REF TO cl_alv_changed_data_protocol.

DATA: lwa_mod_cell TYPE lvc_s_modi,

lwa_row_no TYPE lvc_s_roid,

lwa_column_id TYPE lvc_s_col.

LOOP AT ir_data_changed->mt_mod_cells

INTO lwa_mod_cell.

  • clear : ws_set.

CASE lwa_mod_cell-fieldname.

WHEN c_select. ( selected row)

READ TABLE i_final INTO wa_final

INDEX lwa_mod_cell-row_id.

IF sy-subrc = 0.

CLEAR : ws_set.

wa_final-status = lwa_mod_cell-value.

MODIFY i_final FROM wa_final

INDEX lwa_mod_cell-row_id

TRANSPORTING status .

ENDIF.

ENDLOOP.

ENDFORM. " handle_data_changed

Regards,

Chitra.

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,427

Hello Venkat

If you have defined the appropriate SEL_MODE (LVC_S_LAYO) in the layout an additional "column" is displayed on the left border of the ALV grid to select rows.

The selected rows can be simply retrieved using method go_grid->get_selected_rows( ) (at PAI).

If you do not allow selection of multiple rows (like in the IDoc Monitor, WE02) but want to handle selection of a single row you may use event DELAYED_CHANGED_SEL_CALLBACK.

Regards

Uwe

Read only

Former Member
0 Likes
1,427

Call the method

 get_selected_rows 

. this method will return all the row ids of the rows selected by the user.

Hope this helps.

Thanks,

Balaji

Read only

0 Likes
1,427

This is only HALF the answer as you need to respond to some event before you can get the selected cells.

What you really need to do when selecting rows is to select the rows in the grid normally and then have a toolbar function such as PROCESS.

Then in the ON USER COMMAND you can check for PROCESS - then get the selected rows and do whatever processing you require.

The on data changed / on data changed finished events are actually only entered if you CHANGE data in the grid.

I can post sample code later if you need it.

Cheers

jimbo

Read only

Former Member
0 Likes
1,427

Hi Chitra,

Thanks a lot for your reply, tried the Event - this one and also handle_data_change_finished, i selected the rows and then doubleclicking them, which triggered the event handler method.

Thanks, James, it was very helpful.

Just have a further question to all, if we have a requirement to enable or disable the toolbar on selection of rows , just single click, would that be possible.

Thanks All! I was just looking for some sort of event.

Best,

Venkat