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

using substring in sql where condition

Former Member
0 Likes
2,049

Hello,

I want to write an sql select similar to this one:

select * into wa from dbtab where substr(dbtab~field,2,4) = variable.

where variable is type c length 4.

I know that in various SQL there is a substr function but I can't find a similar one for the SQL used by ABAP...

Thanks.

4 REPLIES 4
Read only

Former Member
0 Likes
1,456

Hi,

you can wildcard text like

select * from dbtab where feild1 = '%like%'

regards

Ramchander Rao.K

Read only

0 Likes
1,456

Yes, but this works for static texts, I want something that will work using a variable instead a static text.

Thank you.

Read only

ThomasZloch
Active Contributor
0 Likes
1,456

Not available in Open SQL, try WHERE field LIKE '__text%' for your example to search for occurrence of "text" in positions 3 to 6 of the column.

Thomas

P.S. you can build the search string using your variable contents.

Read only

Former Member
0 Likes
1,456

if the contents in the table dbtab are only few , you can do the following.

select all the entries from the table into an internal table.

loop at the internal table checking for the required condition on the field.

this would reduce the burden on the database .