Application Development 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: 

Find special characters in string (using mask)

Former Member
0 Kudos

Hi all,

I have the following requirement, perhaps someone has got a hint for me:

I have got a string of 255 characters.

I want to realize that this string only contains characters of a "normal" format, like

a-z, A-Z and numbers.

Any characters like , - # for example are not allowed and I would like to know, how to check my string.

How can I achive that? With FIND or SEARCH?

I am not really familiar with these ABAP KEY WORDS. Can I use masks for example like

DATA: no_good type c value '[#,+,*...)

FIND no_good in STRING

or something like that?

Thanks and best regards

Andreas

1 ACCEPTED SOLUTION

former_member376453
Contributor
0 Kudos

Hi Try the below code:



data: l_data(10) type c,       
      l_special(10) type c.

l_data = 'AAA%%AA'.          " You can give your value here 
L_special = '!@#$%^&*()'.     " This need to be maintained wth the char which you don't want 

IF l_data ca l_special.
 WRITE: 'Special'.


else.
 WRITE: 'Only ALPHA.'.


ENDIF.

P.S. - @ Rob, sorry I haven't check you have already given this as CO. Just a doubt, I think we have to use CA here, because we need to check this for each byte level.

Edited by: Kuntal Nandi on Mar 30, 2009 2:55 PM

7 REPLIES 7

Former Member
0 Kudos

You can check as :

if STRING CA no_good .

*--write your comments ..

endif.

Former Member
0 Kudos

It would be safer to identify those characters that you want to allow and use the CO (contains only) operator. Check its documentation.

Rob

former_member376453
Contributor
0 Kudos

Hi Try the below code:



data: l_data(10) type c,       
      l_special(10) type c.

l_data = 'AAA%%AA'.          " You can give your value here 
L_special = '!@#$%^&*()'.     " This need to be maintained wth the char which you don't want 

IF l_data ca l_special.
 WRITE: 'Special'.


else.
 WRITE: 'Only ALPHA.'.


ENDIF.

P.S. - @ Rob, sorry I haven't check you have already given this as CO. Just a doubt, I think we have to use CA here, because we need to check this for each byte level.

Edited by: Kuntal Nandi on Mar 30, 2009 2:55 PM

0 Kudos

You and Srini identifed the characters that you don't want. But I think that would be dangerous. there are a lot more special characters possible than can be displayed on a standard keyboard. Sinc the OP has said he just wants "normal" characters, it will be safer to figure out what they are and include only them (CO) rather than try to guess at all the other possibilities and exclude them using CA.

Rob

0 Kudos

Rob - got your point. Just to confirm, previously I was trying to do it with CO ,thats why I was late to reply . Probably I am doing something wrong. It should come as 'Only ALPHA.' in the below case, but its coming as

'Special'.


DATA: l_data(10) TYPE c,
      l_special TYPE string.

l_data = 'AAAAA'.


IF l_data CO sy-abcde.
  WRITE: 'Only ALPHA.'.
ELSE.
  WRITE: 'Special'.
ENDIF.

Kuntal

0 Kudos

Me too. I wonder if I have misinterpreted my thinking.

On the other hand, this seems to work:

DATA: f1 TYPE string,
      f2 TYPE string  VALUE 'a=',
      f3 TYPE string  VALUE 'abdA6a'.

CONCATENATE sy-abcde 'abcdefghigklmnopqrstuvwxyz1234567890' INTO f1.

IF f2 CO f1.
  WRITE: /001 f2, 'correct'.
ELSE.
  WRITE: /001 f2, 'incorrect'.
ENDIF.

IF f3 CO f1.
  WRITE: /001 f3, 'correct'.
ELSE.
  WRITE: /001 f3, 'incorrect'.
ENDIF.

Rob

Edited by: Rob Burbank on Mar 30, 2009 4:51 PM

0 Kudos

Hi all,

thanks a lot so far, I have rewarded points.

I will give you a feedback....

Best regards

Andreas