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: 

Its a very urgent task, can anyone please suggest!!

Former Member
0 Kudos

Hi Everyone,

I have a proposal for the find and find next in my screen. Need some help for you people.

In the screen i have around 3 grids, so in the standard toolbar if I press this find button it has to loop through the screen, loop through the grids then columns in the grid and find for the specified string.

So how do I achieve this. Any help will be great use to me.

Thanks in advance,

Prabs.

3 REPLIES 3

athavanraja
Active Contributor
0 Kudos

check out FM

ALV_POPUP_TO_SEARCH2

just pass the search string to C_STRING parameter .

Regards

Raja

0 Kudos

Hi

You can use a routine like this:

PARAMETER: p_search(80) LOWER CASE.

DATA: length_string TYPE i.

length_string = STRLEN( p_search ).

DATA: itab1 LIKE vbrk OCCURS 0,

itab2 LIKE vbrp OCCURS 0.

DATA: gt_fieldcat1 TYPE lvc_t_fcat,

gt_fieldcat2 TYPE lvc_t_fcat.

DATA: rc_search TYPE sy-subrc,

record TYPE sy-tabix,

colunm TYPE alv_s_fcat-fieldname.

START-OF-SELECTION.

PERFORM search_in_table USING itab1[]

gt_fieldcat1

CHANGING rc_search

record

colunm.

IF rc_search <> 0.

PERFORM search_in_table USING itab2[]

gt_fieldcat2

CHANGING rc_search

record

colunm.

ENDIF.

FORM search_in_table U

SING p_table TYPE table

p_fieldcat TYPE lvc_t_fcat

CHANGING rc TYPE sy-subrc

tab_idx TYPE sy-tabix

field TYPE alv_s_fcat-fieldname.

DATA: lt_fieldcat TYPE alv_s_fcat.

FIELD-SYMBOLS: <table> TYPE table,

<wa_table> TYPE ANY,

<field_value> TYPE ANY.

DATA: string TYPE string.

DATA: tabix TYPE sy-tabix.

  • Init

rc = 4.

tab_idx = 0.

CLEAR field.

ASSIGN p_table[] TO <table>.

LOOP AT <table> ASSIGNING <wa_table>.

tabix = sy-tabix.

LOOP AT p_fieldcat INTO lt_fieldcat

WHERE no_out = space.

ASSIGN COMPONENT lt_fieldcat-fieldname

OF STRUCTURE <wa_table>

TO <field_value>.

  • Convert field in a string

MOVE <field_value> TO string.

  • Check string:

IF string CS p_search(length_string).

field = lt_fieldcat-fieldname.

tab_idx = tabix.

rc = 0.

EXIT.

ENDIF.

ENDLOOP.

IF rc = 0. EXIT. ENDIF.

ENDLOOP.

ENDFORM. " SEARCH_IN_TABLE

In your bar create an SEARCH icon, and when the user press it, a popup for searchin is displayed, you could use the FM ALV_POPUP_TO_SEARCH2 (as Raja has written).

Max

Former Member
0 Kudos

In the PAI, when checking the OK code:


case save_ok.
  when '%SC'.                         " find first time
    perform action_find_100_new.
  when '%SC+'.                        " repeat find
    if wfndstrng is initial.
      perform action_find_100_new.
    else.
      perform action_find_more_100_new.
    endif.
endcase.
form action_find_100_new.
  set screen 100.
  perform popup_find.     " display popup window for find
  read table zzdmectl-cols into zselcol
    with key selected = 'X'.
  if sy-subrc = 0.
    zzselcol = zselcol+21(30).
  else.
    clear zzselcol.
  endif.
  if sy-ucomm = 'CON400'.          " continue with find
    clear wfndfnd.                 " init string found
    loop at zzerd_line_item_data_0100. " search for the string
*     from zztop_line.
      if zzselcol is initial.
        if zzerd_line_item_data_0100   cs wfndstrng.
          wzoutpposn = sy-tabix.
          zzdmectl-top_line = sy-tabix.
          wfndfnd = '1'.                  " string found
          exit.
        endif.
      else.
        perform assign_field.
        write <field> to char_field.
        if char_field cs wfndstrng.
          wzoutpposn = sy-tabix.
          zzdmectl-top_line = sy-tabix.
          wfndfnd = '1'.                  " string found
          exit.
        endif.
      endif.
    endloop.
    if wfndfnd is initial.
      message s000 with wfndstrng .
    endif.
  endif.
endform.                    " ACTION_FIND_100_NEW

If you seelct a column, the code will only search the seelcted column; otherwise, it will search the table control.

Form action_find_more_100_new is similar to action_find_100_new, and form popup_find simply calls the screen where you enter the search string.

Rob