Check only ALPHANUMERIC characters

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
karthi_gana
Premium Member
Premium Member
Posts: 729
Joined: Tue Apr 28, 2009 10:49 pm

Check only ALPHANUMERIC characters

Post by karthi_gana »

All,

I have to check whether a string contains only alpha numeric characters.

I used ALPHA() Function, but it is not giving the expected result set.

Input file has
"STREAM GSDW NSC D" - Expected Result Set is OK

"STREAM GSDW1 NSC D" - Expected Result Set is FAILED.

As It contains "1".

ALPHA() or ISVALID(String,DSLInk1.columnname) functions are not returning the expected result set.

Note: The data type of the column is varchar(50)

Inputs are welcome!
Karthik
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Post by rkashyap »

"Alpha" function checks if the given string contains only alphabetic characters. In order to check for alphanumeric characters, use AlNum function.
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post by qt_ky »

It's been a while but I think those functions are strict in that if the string contains whitespace then they will return false. Is that correct? Spaces are not alphabetic nor numeric.
Choose a job you love, and you will never have to work a day in your life. - Confucius
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Post by rkashyap »

I believe that AlNum can handle spaces. Excerpt from example for AlNum function.
Examples. If mylink.mystring1 contains the string "OED_75_9*E", then the following function would return the value 0 (false).
AlNum(mylink.mystring1)

If mylink.mystring2 contains the string "12 red roses", then the following function would return the value 1 (true).
AlNum(mylink.mystring2)
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post by qt_ky »

:!: Do not trust the documentation.

A quick test is in order. Here are a few input strings and function results from version 11.3.1.2.

Code: Select all

AlNum:1 Alpha:1 STRING:Alpha
AlNum:0 Alpha:0 STRING:Alpha with spaces
AlNum:0 Alpha:0 STRING:Alpha_with_underscores
AlNum:1 Alpha:0 STRING:AlphaNumeric123
AlNum:0 Alpha:0 STRING:Alpha Numeric 123 with spaces
AlNum:0 Alpha:0 STRING:Alpha_Numeric_123_with_underscores
AlNum:1 Alpha:0 STRING:123
AlNum:0 Alpha:0 STRING:1 2 3
AlNum:0 Alpha:0 STRING:1_2_3
To answer the original question/expectation, you would first have to remove whitespace then test using Alpha() or AlNum() depending on the desired results.
Choose a job you love, and you will never have to work a day in your life. - Confucius
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Nice test grid! This post ought to be a sticky. THANKS! ; )
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You can always save it as a Favorite.
-craig

"You can never have too many knives" -- Logan Nine Fingers
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Sounds like a good idea.....how does it work? Never used it. I see the "Favorites" link at the top, but don't see how to target a particular post.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

The option to Add to Favorites is on the far right-hand side of the page, both at the very top and bottom of the page/screen. Clicking it will put a link to the topic in your Favorites so you can get back to it easily.
Last edited by chulett on Wed Sep 30, 2015 8:27 pm, edited 1 time in total.
-craig

"You can never have too many knives" -- Logan Nine Fingers
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Cool. Thanks. Never noticed it.
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
karthi_gana
Premium Member
Premium Member
Posts: 729
Joined: Tue Apr 28, 2009 10:49 pm

Post by karthi_gana »

I removed the whitespaces by using stripwhitespace function and then applied ALPHA..But the output of ALPHA is 0 instaed of 1. why?

"STREAM GSDW nsc D"

I used the above string only in my file.
Karthik
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post by qt_ky »

If you did a derivation like Alpha(StripWhiteSpace(Col)) and Col=a b c then it should return 1 for true. If the double quotes are actually part of the string as in Col="a b c" the it should return 0 for false. Check the quote character value you have set when reading the file.
Choose a job you love, and you will never have to work a day in your life. - Confucius
Post Reply