Application Development and Automation 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: 
Read only

Search in Internal Table Utility -- Need Pointers

Former Member
0 Likes
835

Hi all,

I am developing a search utility to arrange a internal table based on ranking ie the internal table should be arranged

based on my search term.

I will have 2 input parameters

1st Input parameter (structure) will have 2 fields "FIELDNAME" "SEARCH STRING" (ITAB1)

2nd Input parameter will be internal table which needs to be searched on.(ITAB2)

Since this search function will be used in many programs i c'nt have defined structure of my internal table

Something like this:

loop at ITAB2.

FIND ALL OCCURRENCES OF ITAB1-SEARCH STRING

IN ITAB2-FIELDNAME (Field name should be the one which is in ITAB1)

How can i get the fieldname which is given as input in my find all occurrence statement??

What kind of structure should be my internal table more of generic form ??

Any pointers will be helpful

Thanks

Bhanu

1 ACCEPTED SOLUTION
Read only

bryan_cain
Contributor
0 Likes
777

If you wanted to find the value in a specific field of the table (and the calling program knows the field it's looking in) you could do the following:


FUNCTION y_test_function.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(INPUT_TAB) TYPE  ANY TABLE
*"     REFERENCE(FIELDNAME) TYPE  STRING
*"     REFERENCE(SEARCH_VALUE) TYPE  STRING
*"----------------------------------------------------------------------

  FIELD-SYMBOLS: <line> TYPE ANY,
                 <field> TYPE ANY.

  DATA: results TYPE match_result_tab.

  LOOP AT input_tab ASSIGNING <line>.
    ASSIGN COMPONENT fieldname OF STRUCTURE <line> TO <field>.
    FIND ALL OCCURRENCES OF search_value IN <field> IGNORING CASE RESULTS results.
  ENDLOOP.

ENDFUNCTION.

Hi all,

I am developing a search utility to arrange a internal table based on ranking ie the internal table should be arranged

based on my search term.

I will have 2 input parameters

1st Input parameter (structure) will have 2 fields "FIELDNAME" "SEARCH STRING" (ITAB1)

2nd Input parameter will be internal table which needs to be searched on.(ITAB2)

Since this search function will be used in many programs i c'nt have defined structure of my internal table

Something like this:

loop at ITAB2.

FIND ALL OCCURRENCES OF ITAB1-SEARCH STRING

IN ITAB2-FIELDNAME (Field name should be the one which is in ITAB1)

How can i get the fieldname which is given as input in my find all occurrence statement??

What kind of structure should be my internal table more of generic form ??

Any pointers will be helpful

Thanks

Bhanu

6 REPLIES 6
Read only

naimesh_patel
Active Contributor
0 Likes
777

FIND ALL OCCURRENCES OF pattern 
  IN TABLE itab table_range

The statement FIND doesn't find the string in any particular column, rather it find the text in entire row.

In your case, you can create a temp table with only a column. Populate that with the data from ITAB2 and use above statement to find the text.

Regards,

Naimesh Patel

Read only

Former Member
0 Likes
777

Hi Bhanu ,

I understood like this , we don't know the structure of itab2 , so how can we check with respect to ITab2,

for this so like this

create data element with type any then assign itab2-field to that type any data element.

data : l_var type any.

loop at itab2.

assign itab2-field to <l_val>

chceck with that <lavl>

Regards

Siva

Read only

bryan_cain
Contributor
0 Likes
778

If you wanted to find the value in a specific field of the table (and the calling program knows the field it's looking in) you could do the following:


FUNCTION y_test_function.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(INPUT_TAB) TYPE  ANY TABLE
*"     REFERENCE(FIELDNAME) TYPE  STRING
*"     REFERENCE(SEARCH_VALUE) TYPE  STRING
*"----------------------------------------------------------------------

  FIELD-SYMBOLS: <line> TYPE ANY,
                 <field> TYPE ANY.

  DATA: results TYPE match_result_tab.

  LOOP AT input_tab ASSIGNING <line>.
    ASSIGN COMPONENT fieldname OF STRUCTURE <line> TO <field>.
    FIND ALL OCCURRENCES OF search_value IN <field> IGNORING CASE RESULTS results.
  ENDLOOP.

ENDFUNCTION.

Read only

0 Likes
777

Hi Bryan,

Thanks for your reply i think your solution is close to what i am looking for:

My only concern is FIELDNAME will be a internal table which will have entries with table field names.

How will i use the below logic there?

Read only

0 Likes
777

Same idea I would think - just put the "assign component" line inside a loop on your field name parameter.

Read only

0 Likes
777

Super like...

tx