Event Class: CL_SALV_EVENTS_TABLE
Following steps are important for ALV event to trigger.
- Create a method for ALV Event to start for instance method double click is used.
- Defind double click method for double click event of class cl_salv_events_table, also we need to mention the method which will be called at time of double click i.e detail method. CLASS-METHODS: handle_double_click FOR EVENT double_click OF cl_salv_events_table IMPORTING row column, detail IMPORTING matnr TYPE matnr.
- Register event handler method for the events of alv SET HANDLER handle_double_click FOR events.
- also defind and impliment detail method.
Following sample code demonstrates ALV event.
REPORT yua_alv_event.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
PRIVATE SECTION.
TYPES: BEGIN OF ty_data,
banfn TYPE banfn,
matnr TYPE matnr,
END OF ty_data.
CLASS-DATA t_data TYPE TABLE OF ty_data.
CLASS-METHODS: handle_double_click
FOR EVENT double_click
OF cl_salv_events_table
IMPORTING row column,
detail
IMPORTING matnr TYPE matnr.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
SELECT banfn matnr
FROM eban
INTO TABLE t_data.
TRY.
cl_salv_table=>factory(
IMPORTING r_salv_table = DATA(alv)
CHANGING t_table = t_data ).
DATA(events) = alv->get_event( ).
SET HANDLER handle_double_click FOR events.
alv->display( ).
CATCH cx_salv_msg.
MESSAGE 'ALV display not possible' TYPE 'I'
DISPLAY LIKE 'E'.
ENDTRY.
ENDMETHOD.
METHOD detail.
TYPES: BEGIN OF alv_line,
matnr TYPE matnr,
maktx TYPE maktx,
END OF alv_line.
DATA alv_tab TYPE TABLE OF alv_line.
SELECT matnr , maktx
FROM MAKT
WHERE matnr = @matnr
INTO CORRESPONDING FIELDS OF TABLE @alv_tab.
IF sy-subrc <> 0.
MESSAGE e007(sabapdemos).
ENDIF.
TRY.
cl_salv_table=>factory(
IMPORTING r_salv_table = DATA(alv)
CHANGING t_table = alv_tab ).
alv->set_screen_popup( start_column = 1
end_column = 60
start_line = 1
end_line = 12 ).
alv->display( ).
CATCH cx_salv_msg.
MESSAGE 'ALV display not possible' TYPE 'I'
DISPLAY LIKE 'E'.
ENDTRY.
ENDMETHOD.
METHOD handle_double_click.
READ TABLE t_data INDEX row ASSIGNING FIELD-SYMBOL(<s_data>).
IF sy-subrc <> 0.
RETURN.
ENDIF.
IF column = 'MATNR'.
demo=>detail( <s_data>-matnr ).
ENDIF.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
Below is the output of above ABAP code.
No comments:
Post a Comment