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

Performance optimization of a string operation

Former Member
0 Likes
926

Hi All,

We have a project requirement of giving an error message if a string has characters other then the ones valid.

Scenario is :

wf_ex field can have characters from alphabets,digits and underscroe and if t has characters other than the ones specified we hav to give an error message

At present we are finding the length of the variable and

we are looping for the number of times of length of the var and chking out if each char is ther in the allowed set of values.

But there is a performance problem in this .Any suggestion in this regardis highly appreciable.

We need to find out if the varirable has any other charcters other than the one specified.

Its very urgent.

regards,

Rajashree

1 ACCEPTED SOLUTION
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
849

HI,

One simple way is this

DATA: var type string.

CONSTANTS: const type string value 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_'.

if var CO const.

*This is valid

else.

invalid.

Regards,

Sesh

endif.

7 REPLIES 7
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
850

HI,

One simple way is this

DATA: var type string.

CONSTANTS: const type string value 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_'.

if var CO const.

*This is valid

else.

invalid.

Regards,

Sesh

endif.

Read only

0 Likes
849

Hi,

We have already doen this but it's not working is ther any other way of doing this.

Regards,

Rajashree

Read only

Former Member
0 Likes
849

Try this one.

data: str(100) type c.

data: str_n type string.

data: str_c type string.

data: str_d type string.

data: str_p type string.

data: len1 type i.

data: ofst1 type i.

str = '#ABCD%123'.

len1 = strlen( str ).

do.

if ofst1 = len1.

exit.

endif.

if str+ofst1(1) co sy-abcde .

concatenate str_c str+ofst1(1) into str_c.

elseif str+ofst1(1) co '0123456789' .

concatenate str_p str+ofst1(1) into str_p.

else.

concatenate str_d str+ofst1(1) into str_d.

endif.

ofst1 = ofst1 + 1.

enddo.

Read only

0 Likes
849

Hi,

We are using this currently ,we need a way such that it can be done in one shot as loop or do would create performance issues.

Regards,

Rajashree

Read only

0 Likes
849

DATA: var type string.

CONSTANTS: const type string value 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_'.

if var CO const.

*This is valid

else.

invalid.

Modify the above example as follows:

CONSTANTS: const type string value 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_ '.

SPACE is there after '_' and try

otherwise try this.

len = strlen( var ).

if var+0(len) CO const.

*valid

else

*invalid

Read only

0 Likes
849

Hi All,

I have found out the solution .

It wud be enough if we use CN.

Thanks a lot for your suggestions.

Read only

Former Member
0 Likes
849

Hi Rajashree,

Try With these FM's.

CLHU_FIND_STRING_IN_TABLE
CPWBBROWSER_SEARCH_FOR_STRING
FC_GET_SEARCH_STRING
STRING_FIND_WORD_FUZZY
G_BOOL_TABLE_CHECK_STRING
CHECK_STRING_ALPHA_SUCCESSOR
CHECK_STRING_DIGIT_SUCCESSOR
CHECK_STRING_SUCCESSOR
CHECK_STRING_SPEC_CHARACTERS
SCP_CHECK_CHARSET_OF_STRING
SF_STRING_CHECK
STRING_COMPARE_FUZZY
SWA_STRING_FIND_ALL
SWF_TASKS_OF_SEARCHSTRING_GET
SD_SOURCE_SEARCH_FOR_STRING
POSED_SEARCH_STRING
POSED_SEARCH_STRING_WPUBON

Regards,

Raghav