02-10-2009 3:41 PM
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...
02-10-2009 3:42 PM
02-10-2009 3:42 PM
02-10-2009 3:47 PM
Hi,
Try this way...
SELECT * FROM konv INTO CORRESPONDING FIELDS OF ls_konv
WHERE ( kschl = 'ZED1' OR
kschl LIKE 'ZD%' ).
02-10-2009 4:00 PM
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
02-10-2009 4:04 PM
> 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
02-10-2009 5:59 PM
* 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