2012 Dec 11 2:43 AM
I wish to initiate a search help for customers which then triggers the standard ALV tool bar Find button. The search help is ready to go but not sure how to trigger the &Find button and pass a value to it without actually pressing it. Could you let me know a good way of handling this?
Thanks
2012 Dec 11 3:29 PM
Hello Mark,
Strange requirement . Anyways,for the fun of learning here are the sequence of steps to be done.
1. Define an event handler in your ALV event handler class as shown below.
handle_search FOR EVENT match_found OF cl_alv_lvc_search_dialog IMPORTING et_search_entries.
2.Implement the Handler as below. The handler is code copied from method ON_MATCH_FOUND of class CL_GUI_ALV_GRID.
METHOD handle_search.
DATA:
ls_cell TYPE lvc_s_cell,
ls_col TYPE lvc_s_col,
ls_roid TYPE lvc_s_roid,
ls_row TYPE lvc_s_row,
ls_search_entries TYPE if_alv_lvc_search=>type_s_search_position.
READ TABLE et_search_entries INTO ls_search_entries INDEX 1.
IF sy-subrc EQ 0.
ls_roid-row_id = ls_search_entries-row.
lr_alv->set_scroll_info_via_id(
is_row_no = ls_roid
is_col_info = ls_col
).
*... backend coordinates
ls_row-index = ls_search_entries-row.
ls_col-fieldname = ls_search_entries-column_name.
lr_alv->set_current_cell_via_id(
is_row_id = ls_row
is_column_id = ls_col
).
* me->select_text_in_current_cell(
* from = ls_search_entries-start_offset
* to = ls_search_entries-end_offset
* ).
cl_gui_cfw=>flush( ).
ENDIF.
ENDMETHOD. "handle_search
3. Create an Instance of the search assistant and call it within your F4 help event handler method.
DATA : lr_search TYPE REF TO cl_alv_lvc_search_dialog,
lt_fcat TYPE lvc_t_fcat,
ls_cell TYPE if_alv_lvc_search=>type_s_search_position,
lt_search TYPE if_alv_lvc_search=>type_t_search_position,
lr_data TYPE REF TO data.
CREATE OBJECT lr_search.
CALL METHOD lr_alv->get_frontend_fieldcatalog
IMPORTING
et_fieldcatalog = lt_fcat.
IF lt_fcat IS NOT INITIAL .
GET REFERENCE OF 'XXXX' INTO lr_data. "->XXXX is your itab used in ALV display
ls_cell-row = 'X'.-> the row number where the F4 help was triggered.
ls_cell-column_name = 'XXXX' -> The column name which is to be searched..
CALL METHOD lr_search->execute
EXPORTING
no_dialog = ' '
acc_mode = ' '
modus = '1'
it_fieldcat = lt_fcat
s_current_cell = ls_cell
IMPORTING
et_search_entries = lt_search
CHANGING
cr_data = lr_data.
ENDIF.
I Hope this helps.
Thanks,
Venkat.
Message was edited by: Venkat Gowrishankar
2012 Dec 11 3:29 PM
Hello Mark,
Strange requirement . Anyways,for the fun of learning here are the sequence of steps to be done.
1. Define an event handler in your ALV event handler class as shown below.
handle_search FOR EVENT match_found OF cl_alv_lvc_search_dialog IMPORTING et_search_entries.
2.Implement the Handler as below. The handler is code copied from method ON_MATCH_FOUND of class CL_GUI_ALV_GRID.
METHOD handle_search.
DATA:
ls_cell TYPE lvc_s_cell,
ls_col TYPE lvc_s_col,
ls_roid TYPE lvc_s_roid,
ls_row TYPE lvc_s_row,
ls_search_entries TYPE if_alv_lvc_search=>type_s_search_position.
READ TABLE et_search_entries INTO ls_search_entries INDEX 1.
IF sy-subrc EQ 0.
ls_roid-row_id = ls_search_entries-row.
lr_alv->set_scroll_info_via_id(
is_row_no = ls_roid
is_col_info = ls_col
).
*... backend coordinates
ls_row-index = ls_search_entries-row.
ls_col-fieldname = ls_search_entries-column_name.
lr_alv->set_current_cell_via_id(
is_row_id = ls_row
is_column_id = ls_col
).
* me->select_text_in_current_cell(
* from = ls_search_entries-start_offset
* to = ls_search_entries-end_offset
* ).
cl_gui_cfw=>flush( ).
ENDIF.
ENDMETHOD. "handle_search
3. Create an Instance of the search assistant and call it within your F4 help event handler method.
DATA : lr_search TYPE REF TO cl_alv_lvc_search_dialog,
lt_fcat TYPE lvc_t_fcat,
ls_cell TYPE if_alv_lvc_search=>type_s_search_position,
lt_search TYPE if_alv_lvc_search=>type_t_search_position,
lr_data TYPE REF TO data.
CREATE OBJECT lr_search.
CALL METHOD lr_alv->get_frontend_fieldcatalog
IMPORTING
et_fieldcatalog = lt_fcat.
IF lt_fcat IS NOT INITIAL .
GET REFERENCE OF 'XXXX' INTO lr_data. "->XXXX is your itab used in ALV display
ls_cell-row = 'X'.-> the row number where the F4 help was triggered.
ls_cell-column_name = 'XXXX' -> The column name which is to be searched..
CALL METHOD lr_search->execute
EXPORTING
no_dialog = ' '
acc_mode = ' '
modus = '1'
it_fieldcat = lt_fcat
s_current_cell = ls_cell
IMPORTING
et_search_entries = lt_search
CHANGING
cr_data = lr_data.
ENDIF.
I Hope this helps.
Thanks,
Venkat.
Message was edited by: Venkat Gowrishankar
2012 Dec 12 5:26 AM
Venkat,
it is slightly strange but a necessary bit of strangeness! However your solution is spot on so thank you very much for taking the time to provide the details. It's much appreciated. Mark
2012 Dec 12 5:39 AM