2013 Nov 11 9:44 AM
i have a company variable and i need to validate it with all abcde...z and 1234567890 .
and i know only one procedure to do this :
if v_comp co 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789''
is there any other way to do in void hard code ??
2013 Nov 11 9:54 AM
Hello,
For the A to Z part u can use the system variable SY-ABCDE.
data g_var type string.
g_var = 'A0131V'.
IF g_var ca sy-abcde and g_var ca '0123456789'.
write 'Alphanumeric'.
ENDIF.
Thanks and Kind Regards,
Yovish.
2013 Nov 11 9:59 AM
2013 Nov 11 10:07 AM
Is this example you are refering to?
A1234567890
Result : Alphanumeric
2013 Nov 11 10:25 AM
Hi Praveen Bindla
Try like this
PARAMETERS : p_data TYPE string.
IF p_data CO '0123456789'.
WRITE: 'NUMERIC ONLY'.
ELSEIF p_data CO sy-abcde.
WRITE: 'ALPHABETS ONLY'.
ELSE.
WRITE: 'ALPHANUMERIC'.
ENDIF.
2013 Nov 11 12:50 PM
The last else statement can include 'space' special symbol ?
2013 Nov 11 9:59 AM
Hi,
Please check this..
You can use the RegEx '[[:punct:]]' to achieve this requirement:
2013 Nov 11 10:21 AM
Hi kusuma ,
am in a class method , the code is in method ,
can u tell with an example .
2013 Nov 11 10:09 AM
Regex can be used. ALNUM stands for alpha-numeric character. Sy-subrc will be zero if string has only alpha-numeric characters.
FIND REGEX '^[[:alnum:]]+$' IN v_comp.
Message was edited by: Manish Kumar
2013 Nov 11 12:54 PM
i have given your same code and executed and given 'a234' as input , but sy-subrc is '4' ..
2013 Nov 11 1:08 PM
The code works for string type.
Your variable is probably of char type, which means trailing spaces, which means you need to search for alpha-numeric, followed by any number of spaces.
DATA v_comp TYPE char10 VALUE 'a123'.
DATA v_comp_str TYPE string VALUE 'a123'.
FIND REGEX '^[[:alnum:]]+$' IN v_comp_str.
WRITE:/ sy-subrc.
FIND REGEX '^[[:alnum:]]+$' IN v_comp.
WRITE:/ sy-subrc.
FIND REGEX '^[[:alnum:]]+\s*$' IN v_comp.
WRITE:/ sy-subrc.
2013 Nov 11 2:06 PM
FIND REGEX '^[[:alnum:]]+$' IN v_comp.
Why do you negate the alpha numeric([[:alnum:]]) character set? The OP wants to check if the input string is alpha-numeric.
I'm a novice in RegEx but i think the following construct looks for aplhanumeric correctly -
Message was edited by: Suhas Saha
Stupid me! Moday afternoon blues
BR,
Suhas
2013 Nov 11 2:23 PM
Hi Suhas
When ^ is used with character set [ ], it works as negation.
When ^ is used at start of pattern, it means start of line.
$ at end of pattern means end of line.
Instead of matching pattern with any substring, I am matching the pattern with full input string by specifying start and end of line.
So, [[:alnum:]] matches any alpha-numeric character, and FIND REGEX means find first occurrence. Your construct with get successful match as 'a', irrespective of subsequent characters. For example gv_compare = 'a123%' will get positive match.
I have checked for 'contains only' by specifying ^ and $.
2013 Nov 11 2:27 PM
2013 Nov 11 2:38 PM
Saw the update right after hitting save button.
Too bad SCN does not show warning that stuff you are replying to has changed.
GMail does alert the user when new email in same thread arrives while drafting a reply.
Even better would be show popup to user saying, 'Hey, you are too slow. 4 new replies came in from the moment you started drafting this lengthy reply ', and one of the buttons would say 'Continue anyways, I don't care'.
2013 Nov 11 2:58 PM
I should have checked once before replying I don't use RegEx regularly & hence tend to forget the syntax.
- Suhas
2013 Nov 12 12:24 PM
2013 Nov 12 1:54 AM
Hi techies,
Am concatenating sy abcde and '0123456789' to var .
And using 'co' to compare it with company code.
So as of now it's comparing correctly.
But manish can you be clear in explaining Regex concept .
Am very new to concept what said.
I want to use your Regex way..
Thanks...
2013 Nov 12 2:29 AM
Hi,
Check program 'DEMO_REGEX_TOY' should help you get a fair idea and play around with REGEX.
Cheers,
Arindam
2013 Nov 12 6:50 AM
2013 Nov 12 9:36 AM
Hi Praveen,
I wonder why this solution that I had posted before was rejected.
If you want to acheive this using REGEX command, use one of the following statement. Both will work fine.
FIND REGEX '[^[:alnum:]]' IN input.
or
FIND REGEX '[^A-Za-z0-9]+' IN input.
IF sy-subrc = 0.
WRITE 😕 'Not alphanumeric ' .
ELSE.
WRITE 😕 'Alphanumeric'.
ENDIF.
2013 Nov 18 10:21 AM
if sy-subrc = 0 . then it should be alpha neumaric right ?
and if sy-subrc neq 0 then its not alpha neumaric ?
2013 Nov 18 10:29 AM
No, its the way I have written.
If sy-subrc = 0 , it means that it has come across some character that is not alphanumeric.
if sy-subre ne 0, it means it has not found any character that is not alphanumeric. Hence its an alphanumeric string.
2013 Nov 18 10:36 AM
Hi sushmitha ,
i have checked ur code , but it is always showing the sy=subrc as 0
either for alpha neumaric or non alpha neumaric .
i have given input as 'A1234' and '@1234' for both cases it was giving sy-subrc = 0 .
FYI : my input is char type .
2013 Nov 18 10:41 AM
Well, this is my complete code. And its always working correctly for me whichever statement I use. FIND REGEX '[^[:alnum:]]' IN input or FIND REGEX '[^A-Za-z0-9]+' IN input.
DATA : input TYPE string.
input = 'a234a%##y4'.
WRITE 😕 input.
FIND REGEX '[^[:alnum:]]' IN input.
*FIND REGEX '[^A-Za-z0-9]+' IN input.
IF sy-subrc = 0.
WRITE 😕 'Not alphanumeric ' .
ELSE.
WRITE 😕 'Alphanumeric'.
ENDIF.
Output on changing the value of input
Note : Data type is string.
2013 Nov 18 10:46 AM
Instead of Char Type use String Type .
PARAMETERS: input type string .
FIND REGEX '[^A-Za-z0-9]+' IN input.
IF sy-subrc = 0.
WRITE :/ 'Not alphanumeric ' .
ELSE.
WRITE :/ 'Alphanumeric'.
ENDIF.
Regard's
Smruti
2013 Nov 18 10:48 AM
Cheers ,
urs is working only for string type .
but what if my input is char type ?
2013 Nov 18 10:50 AM
If you are using char type, then there is a small change to the regex.
FIND REGEX '[^[:alnum:]\s]' IN input.
or
FIND REGEX '[^A-Za-z0-9\s]+' IN input.
2013 Nov 18 10:54 AM
2013 Nov 18 10:57 AM
if u dont mind can you explain me .
see REGEX checks for a-z or 0-9 in input then if it finds then sysubrc should 0 .
and if it finds special character then it should ne 0 .
but in ur case its vice versa ?
2013 Nov 18 11:21 AM
'[^A-Za-z0-9]+'
This character ^ is the negation of a value set.
So when ^ is added to the expression, it will find a character that is not in A-Z, a-z, 0-9.
The search is for any character outside this set. So when it comes across one such character, sy-subrc becomes 0 and you know that its not alphanumeric.
If sy-subrc ne 0, it means the regex could not find any character that is not in the given set, hence its purely alphanumeric.
Hope its clear now. 🙂
2013 Nov 18 12:15 PM
2024 Oct 21 1:23 PM
It is giving sy-subrc = 4 for both alpahnumeric and non-alphanumeric values.
2013 Nov 12 5:23 AM
2013 Nov 12 5:24 AM
You can use the FM CONVERSION_EXIT_ALFAN_INPUT.
This would give an error if any special character is entered, only alphabets, numbers and underscore is allowed.
2013 Nov 12 10:10 AM
Susmitha,
But he will got error by using this FM if his string or variable contains any space or invalid char.
Regards
Vivek
2013 Nov 12 12:23 PM
Hello manish ,
i checked your solution , it worked .
Thanks ..