Application Development 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: 

ALV Trigger &Find button

Former Member
0 Kudos
313

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos
119

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

3 REPLIES 3

Former Member
0 Kudos
120

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

0 Kudos
119

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

0 Kudos
119

Reply by tagged as Correct Answer, discussion marked as "Answered".

Regards, Vinod