ref_alv_table TYPE REF TO tt_usr,
GET REFERENCE OF lt_usr INTO event_handler->ref_alv_table.
REPORT z_my_test.
*----------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
TYPES:
* Define a table type, you can use it to store the reference
* on the internal table. In this case it is the same as the
* table (in which case it is superfluous), but this can be used
* to define only a sub-set of the fields.
tt_usr TYPE TABLE OF usr02 WITH DEFAULT KEY.
* Static attributes to store references on your local variables
DATA:
* Reference on the internal table with data
ref_alv_table TYPE REF TO tt_usr,
* Reference on the ALV object
ref_alv TYPE REF TO cl_salv_table.
METHODS constructor
IMPORTING
i_alv TYPE REF TO cl_salv_table.
METHODS on_link_click
FOR EVENT if_salv_events_actions_table~link_click
OF cl_salv_events_table
IMPORTING row column.
ENDCLASS. "lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
METHOD constructor.
ref_alv = i_alv.
ENDMETHOD. "constructor
METHOD on_link_click.
"... find clicked row using the table reference
TRY.
DATA(usr_record) = ref_alv_table->*[ row ].
cl_abap_browser=>show_html( html = VALUE #( ( usr_record-bname && |</br>| )
( |Created by - | && usr_record-aname ) ) ).
CATCH cx_sy_itab_line_not_found.
"Error message goes here
ENDTRY.
" If something changed...
DATA(something_changed) = abap_false.
IF something_changed = abap_true.
"...then refresh.
ref_alv->refresh( ).
ENDIF.
ENDMETHOD. "on_link_click
ENDCLASS. "lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS lcl_routines DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_routines DEFINITION.
PUBLIC SECTION.
METHODS display_alv.
ENDCLASS.
*----------------------------------------------------------------------*
* CLASS lcl_routines IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_routines IMPLEMENTATION.
METHOD display_alv.
DATA:
lt_usr TYPE lcl_event_handler=>tt_usr. " <- local internal table
SELECT * FROM usr02
UP TO 30 ROWS
INTO CORRESPONDING FIELDS OF TABLE @lt_usr
ORDER BY bname.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = DATA(alv)
CHANGING
t_table = lt_usr.
" Instantiate the event handler passing a reference
" To the ALV object which can be used within the event handler
DATA(event_handler) = NEW lcl_event_handler( alv ).
" Register event handler
DATA(lo_events) = alv->get_event( ).
SET HANDLER event_handler->on_link_click FOR lo_events.
" Get and store the reference on your local internal table
GET REFERENCE OF lt_usr INTO event_handler->ref_alv_table.
" Also store the reference on the ALV object, it can be useful
event_handler->ref_alv = alv.
" Set column as hotspot
DATA(columns) = alv->get_columns( ).
DATA(column) = CAST cl_salv_column_list( columns->get_column( 'BNAME' ) ).
column->set_cell_type( if_salv_c_cell_type=>hotspot ).
alv->display( ).
CATCH cx_salv_msg. " cl_salv_table=>factory()
"Ideally raise a message instead of WRITE statements
WRITE: / 'cx_salv_msg exception'.
CATCH cx_salv_not_found. " cl_salv_columns_table->get_column()
WRITE: / 'cx_salv_not_found exception'.
ENDTRY.
ENDMETHOD. "display_alv
ENDCLASS.
*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
DATA(lcl) = NEW lcl_routines( ).
lcl->display_alv( ).
REPORT z_my_salv_template.
*----------------------------------------------------------------------*
* CLASS lcl_routines DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_routines DEFINITION.
PUBLIC SECTION.
METHODS display_alv.
PRIVATE SECTION.
* Attributes to store references on your local variables
DATA:
* Reference on the internal table with data
data_table TYPE STANDARD TABLE OF usr02 WITH DEFAULT KEY,
* ALV object
alv TYPE REF TO cl_salv_table.
METHODS on_link_click
FOR EVENT if_salv_events_actions_table~link_click
OF cl_salv_events_table
IMPORTING row column.
ENDCLASS. "lcl_routines DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_routines IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_routines IMPLEMENTATION.
METHOD display_alv.
SELECT * FROM usr02
UP TO 30 ROWS
INTO CORRESPONDING FIELDS OF TABLE @data_table
ORDER BY bname.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = alv
CHANGING
t_table = data_table.
" Register event handler
DATA(lo_events) = alv->get_event( ).
SET HANDLER me->on_link_click FOR lo_events.
" Set column as hotspot
DATA(columns) = alv->get_columns( ).
DATA(column) = CAST cl_salv_column_list( columns->get_column( 'BNAME' ) ).
column->set_cell_type( if_salv_c_cell_type=>hotspot ).
alv->display( ).
CATCH cx_salv_msg. " cl_salv_table=>factory()
"Ideally raise a message instead of WRITE statements
WRITE: / 'cx_salv_msg exception'.
CATCH cx_salv_not_found. " cl_salv_columns_table->get_column()
WRITE: / 'cx_salv_not_found exception'.
ENDTRY.
ENDMETHOD. "display_alv
METHOD on_link_click.
"... find clicked row using the table reference
TRY.
DATA(usr_record) = data_table[ row ].
cl_abap_browser=>show_html( html = VALUE #( ( usr_record-bname && |</br>| )
( |Created by - | && usr_record-aname ) ) ).
CATCH cx_sy_itab_line_not_found.
"Error message goes here
ENDTRY.
" If something changed...
DATA(something_changed) = abap_false.
IF something_changed = abap_true.
"...then refresh.
alv->refresh( ).
ENDIF.
ENDMETHOD. "on_link_click
ENDCLASS. "lcl_routines IMPLEMENTATION
*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
DATA(lcl) = NEW lcl_routines( ).
lcl->display_alv( ).
cl_abap_browser=>show_html( html = VALUE #( ( usr_record-bname ) ).
OR
cl_abap_browser=>show_html( html = VALUE #( ( 'Here is my static text' ) ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |