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: 

Using wildcard character * in where condition of select statement...

Former Member
0 Kudos

hi friends,

can any one help me how to write a select statement using wildcard character '*' in the where condition?

for example:

SELECT * FROM konv INTO CORRESPONDING FIELDS OF ls_konv

WHERE ( kschl = 'ZED1' OR

kschl = 'ZDP1' OR

kschl = 'ZDQ1' OR

kschl = 'ZDPM' OR

kschl = 'ZDQM' )

i want to write the same above code as

SELECT * FROM konv INTO CORRESPONDING FIELDS OF ls_konv

WHERE ( kschl = 'ZED1' OR

kschl = 'ZD*' ).

i want to fetch all the records which are starting with ZD (say ZD*) for the field KSCHL.

so how can i write the same in the select statement???

thanks in advance...

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Search the forum for the keyword 'LIKE'.

5 REPLIES 5

Former Member
0 Kudos

Search the forum for the keyword 'LIKE'.

Former Member
0 Kudos

Hi,

Try this way...

SELECT * FROM konv INTO CORRESPONDING FIELDS OF ls_konv
WHERE ( kschl = 'ZED1' OR
kschl LIKE 'ZD%' ).

MarcinPciak
Active Contributor
0 Kudos

Hi murashali,

You can use this code snippet


data: begin of it_ranges occurs 0,
          sign type c,
          option(2) type c,
          low type konv-kschl,
          high type konv-kschl,
        end of it_ranges.

"first condtion
it_ranges-sign = 'I'.
it_ranges-option = 'EQ'.
it_ranges-low = 'ZED1'.
append it_ranges.

"second one
it_ranges-option = 'CP'.     "LIKE
it_ranges-low = 'ZD%'.
append it_ranges.

SELECT * FROM konv INTO CORRESPONDING FIELDS OF ls_konv
WHERE 
kschl in it_ranges.

What it does is creating two conditions (combined with OR). Second one is looking for pattern ZD% which will result in all ZD* entries.

Anyhow from performance point of view the above solution is not recommended. Avoid OR combined conditions in where clause (especially the inner ones like


( kschl = 'ZED1' OR kschl = 'ZD*' ) 

Instead we can substitiute it with:


SELECT * FROM konv INTO CORRESPONDING FIELDS OF ls_konv
WHERE kschl IN ('ZED1', 'ZDP1', 'ZDQ1', 'ZDPM', 'ZDQM' ).

This one will be much better for DB optimizer and will gain in performance increase.

Regards

Marcin

0 Kudos

> WHERE kschl IN ('ZED1', 'ZDP1', 'ZDQ1', 'ZDPM', 'ZDQM' ).

- you'll have to update the code anytime there is a new ZD* value

- this is passed to the database as a chain of OR-conditions...

Thomas

0 Kudos

  • * you'll have to update the code anytime there is a new ZD* value

He gave hardcoded values, thus this is applicable.

  • * this is passed to the database as a chain of OR-conditions...

Yup, but is more efficient than using LIKE ZD%. Still more efficient than inner OR (as far as there are more key fields to determine). In this case (one key field) is however similar.

Regards

Marcin