2008 Jun 17 11:44 AM
Hi
I have a requirement in which I have document header text(BKPF-BKTXT) on selection screen.The user can enter wildcard characters also in the search.For e.g if user enters (test) then it should retrieve all the possible records starting with test.The records can be test123,TEST123,Test123,TEst123,TESt123,tEst123..etc.for eg if user enters Test then also it should return all the possible header texts starting with test.
Please advise.
Regards
2008 Jun 17 11:47 AM
Hi,
From the selection screen,fetch 'TEST'.Put it in some variable.Replace TEST by TEST%.In the select query write.:
var = 'TEST%'.
select f1 from <table>
where f1 like var.
2008 Jun 17 11:56 AM
Hi,
{*} needs to be replaced with %.
? needs to be replaced with _ while fetching the values from table.
If you want to use ? or {} as it is then you have use some escape character. In this case, {} needs to be replaced with #%.
? needs to be replaced with #_ . Here escape character is #
select * from <table> into table <internal table> where <column> like mod_search_pattern
escape '#'.
Reward points if useful.
Regards,
Siva.
2008 Jun 17 12:05 PM
If you are using selection screen as you mentioned in your question, you can simply use 'Select-options' to get user input.
You can use select-options with addition of "NO-EXTENSION" and "NO INTERVALS". This way user will see a single field just like a parameter but in fact it is a select-option so you can simply use it in you select statement without any conversion. e.g.
select * from bkpf where bktxt in s_bktxt.
The pattern matching logic is handeled by select-option itself.
2008 Jun 17 12:41 PM
Hi,
Refer the example code :
data : str(20) type c,
num type n.
str = 'SAP'.
num = strlen( str ).
str+num(1) = '%'.
write : str.
"Now you can use str in select statement using LIKE operator.
Thanks,
Sriram Ponna.
2008 Jun 17 12:46 PM
HI,
You need not modify the select option, if you enter * in the selct option, then option will have "CP", so the selct statement fetches all the data starting with test* ,
Thanks,
Keerthi.
2008 Jun 17 12:48 PM
HI,
You can use LIKE in the SELECT statement when you are using wild characters in WHERE class. Check the belwo code...
Concatenate p_bktxt '%' into v_bktxt.
SELECT .....From BKPF INTO TABLE i_bkpf WHERE BKTXT LIKE v_bktxt.
Rgds,
Bujji
2008 Jun 17 2:23 PM
But I can't see how any of the solutions posted so far can cope with the mixture of upper and lower case ?
I had a requirement similar to this recently, what I did was to have a select option on BKTXT, loop through it converting to upper case, not use it at all in the WHERE clause of the SELECT, go through the iinternal table of data returned copying BKTXT and converting it to upper case in a new column, and then looping at the itab where the upper case BKTXT is in the select option. Not exactly elegant or efficient but can't see any other way around it.
2008 Jun 17 2:33 PM
This can be done quite simply using native SQL. There are lots of examples posted in the forum.
Rob
2008 Jun 17 2:41 PM
2008 Jun 17 2:43 PM
Hi
Did u get the correct output for mixture of characters(lower and uppercase).
Could you please send the code for this?
Thanks
2008 Jun 17 2:51 PM
As I said, there are plenty of examples on the forum. All you have to do is look for them.
Rob