on 11-30-2005 10:36 AM
I would like to use a SQL stmts like this:
SELECT * FROM tab WHERE key1 LIKE '%<i>variable</i>%'.
Using LIKE in the WHERE clause requieres a character field. But I want to use a vairable...
how should i write that?
thx,
holger
Hi Holger,
You can do like this also.
Declare a range table like this.
RANGES: R_VBELN FOR VBAK-VBELN. (You can declare your own variable type here.)
Then populate the variable into the Ranges like this.
R_VBELN-LOW = VARIABLE.
R_VBELN-SIGN = 'I'.
R_VBELN-OPTION = 'CP'.
APPEND R_VBELN.
CLEAR R_VBELN.
Then write a select like this.
SELECT * FROM TABLE WHERE VBELN IN R_VBELN.
The above select will achieve the same functionality.
Thanks,
Sreekanth
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Holger,
You can use 'LIKE' for Character string or variable in
Where clause of Select statement.
Pass the value which needs to be compared into a variable and use that variable in the select statement.
Example:
Data: v_ltext like cskt-ltext value 'abc%abc'.
Select * from CSKT
Into table itab
where ltext like v_ltext.
Regards,
Sudhakar.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
data str(100).
data val type i.
now you can dynamically set the value for str..like-->
case flag.
when '1'.
val = value for flag 1.
str = concatenate 'key1 eq ' val into str.
when '2'.
val = value for flag 1.
str = concatenate 'key1 eq ' val into str.
endcase.
SELECT * FROM tab WHERE str.
i hope it will solve your problem.
Message was edited by: Anid
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Holger,
1. Just a slight change in sql
2. Instead of hardcode ther where condition with LIKE statement we have to CONSTRUCT the whole condition
in a variable and use.
3. WHERE (source_text)
source_text is a variable -- maybe (100) type c.
4. Just consturct the source_text
using CONCATENATE
so that it contains
key1 like '%ABC'.
5. It will work.
6. Make proper use of concatenate and variable
and proper Quotes '
otherwise sql at runtime will give error.
Regards,
Amit M.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
Check out this sample code.
concatenate sy-cprog '%' into <b>w_bdcerr</b>.
SELECT * FROM APQI UP TO 1 ROWS
WHERE GROUPID LIKE <b>W_BDCERR</b> AND
QSTATE NE 'F'.
ENDSELECT.
You concatenate the variable and % into a string and use that in select. This meets your requirement.
Regards,
Sailaja.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
This variant of SELECT Clause wont support varible handling here..
Check the below link as well..
http://help.sap.com/saphelp_46c/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm
Regards,
Abdul
Message was edited by: Abdul Hakim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
8 | |
7 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.