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

Query regarding select

Former Member
0 Likes
722

How do i do string comparisons in the where clause of a select.

Something like:

data: c(20).

c = 'Music'.

Select a b from yplaylist into table i_playlist where

a CO c.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
702

HI Asha,

If you want the exact string to be matched, then you can directly uuse

Select a b from yplaylist into table i_playlist where

a = c.

If you want a matchin the patterns, i.e. all the strings that contain a string 'Music', then use like syntax.

Select a b from yplaylist into table i_playlist where

a like '%Music%'.

8 REPLIES 8
Read only

Former Member
0 Likes
702

u have where a LIKE C.

operator LIKE to compare in where clause chck that..

reward if it helps uu..

Read only

Former Member
0 Likes
702

Select a b from yplaylist into table i_playlist where

a eq c.

Read only

Former Member
0 Likes
703

HI Asha,

If you want the exact string to be matched, then you can directly uuse

Select a b from yplaylist into table i_playlist where

a = c.

If you want a matchin the patterns, i.e. all the strings that contain a string 'Music', then use like syntax.

Select a b from yplaylist into table i_playlist where

a like '%Music%'.

Read only

0 Likes
702

Hi Ravi,

I want to get the various values from table which is exactly or contains music. So instead of hardcoding , can i just use

Select a b from yplaylist into table i_playlist where a like c.

Read only

0 Likes
702

if u dont want to hardcode then declare the variable and use in select statement.

date: g_cat(7) type c value '%Music%'.

Read only

0 Likes
702

No the value keeps changing. So i capture it in a variable and do the comparison. So it has to be dynamic.

Read only

0 Likes
702

To Do that you ave to concatenate '%' in front and after the actual word.

Assume that the word you want to check is in a variable v_word.

then do like this:

concatenate '%' v_word '%' into c.

Select a b from yplaylist into table i_playlist where a like c.

Regards,

Ravi

Read only

Former Member
0 Likes
702

Hi,

Try this

Select a

b

from ypaylist

into table i_paylist

where a = c.

if sy-subrc eq 0.

endif.