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

validate that a string is composed from a defined character set

Former Member
0 Likes
754

Hi experts,

I need to validate that a string enetered as parameter is composed of the following character set :

26 alphabets (both in capital or lower case), a “’” (like O’Brien), a blank between characters like (Mc Donald). So the total valid characters on any of these fields will be 54.

could You provide with an efficient code ?

Plz Help....

rewards gauranteed........

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
693

Hi,

Use variable CA { a,b,c}

Reward points

4 REPLIES 4
Read only

Former Member
0 Likes
694

Hi,

Use variable CA { a,b,c}

Reward points

Read only

Former Member
0 Likes
693

Hi,

Please find the folowing code.

Use the comparing operator 'CO'. On right side you can write all your 54 possible characters.

data : str1 type string value 'eCA d'.

if str1 Co 'ABCdefghijklmnopqrstuvwx yz*'.

break-point.

endif.

reward if it helps.

regards,

mahantesh

Read only

Former Member
0 Likes
693

Hi,

Check the below code.

data: var(52) type c Value 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.

data: v1(14) type c value 'welcome to SDN'.

data: v2 type i.

data: v3 type i.

v3 = 0.

v2 = STRLEN( v1 ).

do v2 times.

if v1+v3(1) = space .

write:/ 'test contains character space'.

elseif v1+v3(1) ca var.

write:/ 'test'.

elseif v1(v3) = '/'.

write:/ 'test contains character /'.

endif.

v3 = v3 + 1.

enddo.

Regards,

Shravan G.

Read only

BGarcia
Active Contributor
0 Likes
693

Hello,

You can use regular expressions for validating the characters.

For example:

DATA: lv_string TYPE string VALUE 'My Name is O''Neill'.

DATA: lv_pattern TYPE string VALUE '[a-zA-Z| |'']+'.

DATA: lv_result TYPE boolean.

lv_result = CL_ABAP_MATCHER=>MATCHES( pattern = lv_pattern text = lv_string ).

If lv_result is X, it is OK. If is empty, then a invalid character is in the string.

Regards.