SALV - kazumov/abap GitHub Wiki
sources: https://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=117506242 http://www.erpworkbench.com/abap/dialog/basic-dialog.htm
Building
Starting with the program below, we will add coding to handle some events for the ALV Grid. In this example the events DOUBLE_CLICK and ADDED_FUNCTION will be handled.
The data definition
report z_savl.
data: ispfli type table of spfli.
data: xspfli type spfli.
data: gr_events type ref to cl_salv_events_table.
data: gr_table type ref to cl_salv_table.
data: gr_selections type ref to cl_salv_selections.
select * into corresponding fields of table ispfli from spfli up to 100 rows.
Event handler definition
class lcl_handle_events definition.
public section.
methods:
on_user_command for event added_function of cl_salv_events
importing e_salv_function,
on_double_click for event double_click of cl_salv_events_table
importing row column.
endclass.
The data definition (cont.)
data: event_handler type ref to lcl_handle_events.
Start of selection
start-of-selection.
Create the SALV object
call method cl_salv_table=>factory
importing
r_salv_table = gr_table
changing
t_table = ispfli.
The SALV table screen status
gr_table->set_screen_status(
pfstatus = 'SALV_TABLE_STANDARD'
report = sy-repid
set_functions = gr_table->c_functions_all ).
Events handling
gr_events = gr_table->get_event( ).
create object event_handler.
set handler event_handler->on_user_command for gr_events.
set handler event_handler->on_double_click for gr_events.
Set up selections.
gr_selections = gr_table->get_selections( ).
gr_selections->set_selection_mode( 1 ). "Single row selection
Display
gr_table->display( ).
Events handler implementation.
class lcl_handle_events implementation.
* TOOLBAR_BUTTON_CLICK
method on_user_command.
* Get the selection rows
data: lr_selections type ref to cl_salv_selections.
data: lt_rows type salv_t_row.
data: ls_rows type i.
data: message type string.
case e_salv_function.
when 'MYFUNCTION'.
lr_selections = gr_table->get_selections( ).
lt_rows = lr_selections->get_selected_rows( ).
read table lt_rows into ls_rows index 1.
read table ispfli into xspfli index ls_rows.
concatenate xspfli-carrid xspfli-connid
xspfli-cityfrom xspfli-cityto
into message separated by space.
message i001(00) with 'You pushed the button!' message.
endcase.
endmethod.
* DOUBLE_CLICK
method on_double_click.
data: message type string.
data: row_c(4) type c.
row_c = row.
concatenate 'Row' row_c 'Column' column into message separated by space.
message i001(00) with 'You double-clicked on ' message.
endmethod.
endclass.
Handlers
https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abapset_handler_instance.htm