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

select with spacing

Former Member
0 Likes
3,712

Hi all,

I need to do a SELECT statement on a field, but the field may contain spaces

e.g.

IBCU354355-1 could be IBCU 354355-1 or IBCU354355 - 1 etc...

Is this possible

Thanks

Hi all,

I need to do a SELECT statement on a field, but the field may contain spaces

e.g.

IBCU354355-1 could be IBCU 354355-1 or IBCU354355 - 1 etc...

Is this possible

Thanks

13 REPLIES 13
Read only

Former Member
0 Likes
2,822

Hi,

Before selecting the data, you can use the CONDENCE statment to remove the spaces, then use the varibale to get the data

Regards

Sudheer

Read only

Former Member
0 Likes
2,822

Use LIKE and wildcard % in your where clause.

SELECT...

WHERE <fieldname> LIKE 'IBCU%354355%'

Read only

0 Likes
2,822

> Use LIKE and wildcard % in your where clause.

>

> SELECT...

> WHERE <fieldname> LIKE 'IBCU%354355%'

I need to build up the field like this - but wont know where the spaces could occur.

That is the problem

Read only

0 Likes
2,822

In that case then you will have to select the field first and use CONDENSE <fieldname> NO-GAPS to remove the spaces.

Read only

Former Member
0 Likes
2,822

select the field......then move it to charecter type variable......then use CONDENSE <> NO-GAPS.

to remove spaces.

Regards

Vasu

Read only

Former Member
0 Likes
2,822

Hi,

You can use CS command

c1 contains the character string c2.

Trailing blanks in c1 and c2 are ignored if the respective field is of type C.

An empty string c2 (i.e., only blanks with type C, or empty string with type STRING) is included in any string c1, including the empty string itself. On the other hand, there is no non-empty string c2 included in an empty string c1.

If the result of the comparison is positive, the system field SY-FDPOS contains the offset of the first character of c2 in c1.

If the result of the comparison is negative, the system field SY-FDPOS contains the length of c1.

The comparison is not case-sensitive.

In select query you can write:

where field CS sapce.

Hope it works.

Thanks,

Sandeep.

Read only

Former Member
0 Likes
2,822

Yes, it is possble.

For example - When you select Material Description( MAKT-MAKTX), it may contain space, special chars etc. But you can see them it reports. Don't you ?

Read only

Former Member
0 Likes
2,822

CONDENSE would not work as then it will look for the condensed "no spaces" version in the table and would not select the ones with the spaces any more.

The LIKE % would work if I could guarantee that in that position there would be a %.

what i was thinking of doing is doing a replace

replacing spaces with % and then doing a like command...

What do you think?

Read only

Former Member
0 Likes
2,822

% is a true wildcard, so it will still work even if there is nothing in that space.

For example, IBCU%354 would find both IBCU354 and IBCU 354

Read only

0 Likes
2,822

> % is a true wildcard, so it will still work even if

> there is nothing in that space.

>

> For example, IBCU%354 would find both IBCU354 and

> IBCU 354

I agree, but it wouldnt find

IBCU354 1234 because space is in different location.

Read only

Former Member
0 Likes
2,822

Depending on your database, you <u>may</u> be able to achieve this with native SQL. Check with your DBAs to see if they know of any syntax for this.

Rob

Read only

0 Likes
2,822

thanks for the replies...

I think I will just loop through the field and check each item if its a space convert it to %.

How does that sound

Read only

0 Likes
2,822

What if the text contains an actual '%'?

Rob