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

Select Query with Like statement

Former Member
0 Likes
3,369

Hi every one,

My requirement is, user will enter part of the employee name.I need to search the employees whose name contains the word entered by the user.For that I have used the following query.Functionality wise,It is working fine.But its taking more time.Please kindly advise me how can I improve the performance.

concatenate '%' user_input '%' into v_user_inp_pattern .

Select emp_name from <Database table> into table <internal table> where emp_name like v_user_inp_pattern.

Thanks,

Selva

10 REPLIES 10
Read only

Former Member
0 Likes
1,216

First get the data from database table into an internal table on the basis of primary key.

Now use loop with where clause to read the required user name.

This method will fetch all the data from the database table still can be faster as in present approach no key is used .

Also, you can contact basis to create a secondary index on the fields you are using.

hope this may help you.

Read only

Former Member
0 Likes
1,216

But the table which I used is the master one.It contains more than 2 Lakhs record.

Read only

0 Likes
1,216

Try to use primary key of the database table as follows :

*-- Declare fields as initial.

CONSTANTS: c_vbeln TYPE vbfa-vbeln VALUE IS INITIAL,

c_posnn TYPE vbfa-posnn VALUE IS INITIAL,

c_vbtyp_n TYPE vbfa-vbtyp_n VALUE IS INITIAL.

*-- Use this in select query

SELECT vbelv posnv vbeln posnn vbtyp_n rfmng meins

INTO TABLE gi_vbfa FROM vbfa

WHERE vbelv IN s_vbeln

AND posnv IN s_posnv

AND vbeln GE c_vbeln

AND posnn GE c_posnn

AND vbtyp_n GE c_vbtyp_n.

This will fetch data using primary key and will improve results.

Read only

Former Member
0 Likes
1,216

Hi,

you can do it this way....

RANGES : r_user_input for v_user_inp_pattern.

r_user_input-sign = 'I'.
r_user_input-sign = 'CP'.
concatenate '*' user_input '*' into r_user_input-low.
append r_user_input.

Select emp_name from <Database table> into table <internal table> where emp_name in r_user_input.

This will improve your performance to a lot more extent.

Regards,

Siddarth

Read only

HermannGahm
Product and Topic Expert
Product and Topic Expert
0 Likes
1,216

Hi Selva,

if that is your only where condition...


Select emp_name from <Database table> into table <internal table> where emp_name like v_user_inp_pattern.

depending on db... and indexes you have to do one of this 4 options:

a big range scan (with client, if the table is client dependent) -> expensive

a full table scan

a full index scan

a fast full index scan

the last one would probably be the fastest... and only possible if you are

running on ORACLE and your index contains emp_name.

If you could change your wild card to:

concatenate user_input '%' into v_user_inp_pattern .

it would be different... and faster solutions would become possible.

Kind regards,

Hermann

However all options have to touch ALL records... (in index blocks and or table blocks)

Read only

Former Member
0 Likes
1,216

> First get the data from database table into an internal table on the basis of primary key.

it is better to think twice before you write such nonsense!

Only the last answer is useful.

Overall, what do you expect?

You should try to offer a search, which uses a wildcard only at the end 'abcd%' is dramatically faster

than '%bcde%'. The second one is a full search of the whole content, there is not much you can do.

Siegfried

Read only

Former Member
0 Likes
1,216

What's the table?

Rob

Read only

Former Member
0 Likes
1,216

This message was moderated.

Read only

Former Member
0 Likes
1,216

@Rob,

this question is completely out-dated, why do you ask?

Read only

0 Likes
1,216

Hi Siegfried - did you see the date of my question

The OP had marked this as closed and included a meaningless message like 'resolved' or something. That brought it up to the top of the list. So I deleted that comment, leaving my old one as the last.

Rob