Verify if given string is of Decimal type or not

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
nitingupta
Participant
Posts: 22
Joined: Fri Jul 26, 2013 9:43 am
Location: PUNE

Verify if given string is of Decimal type or not

Post by nitingupta »

Hi All,
I need to validate a given string in DS server jobs. Check If the given string is decimal or not.For Parallel jobs i can use IsValid(Decimal[m,n],MyString) function in transformer stage, however in Server jobs i am not able to find anything similar to perform that. Can someone help me on that.

for e.g. Column1 - decimal[5,2]
Values to reject - 123.444, 1234.567
Values to pass - 123.45, -123.45

Thanks,
Nitin Gupta
NITIN GUPTA
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You would have to roll your own, typically in a custom BASIC routine. Been a while but thinking perhaps ICONV with an MD conversion code then check the status of the result? That or just wait for Ray to wander by and chime in. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
nitingupta
Participant
Posts: 22
Joined: Fri Jul 26, 2013 9:43 am
Location: PUNE

Post by nitingupta »

Thanks craig, I am trying with ICONV and MD conversion but not yet getting desired results. Meanwhile i will keep digging in it. If any other suggestions there please let me know.
NITIN GUPTA
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Whatever you do, don't "test" this using a job but rather the build-in testing capability of the routine editor. Keep it simple so you can rapidly throw many different input strings into it then pass out the status of the conversion as the "answer". And in case you've not used it before, you would use the STATUS function to check the success of the conversion.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Num() function will report whether the value is numeric. That may suffice for your subject requirement. It even handles scientific notation, such as 6.023E23.

It seems, however, that you are interested in answering the question "is this a decimal number with exactly five significant digits and exactly two decimal places?". The Matches operator is our friend here.

Code: Select all

Ans = (inLink.TheString Matches "3N'.'2N")
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
nitingupta
Participant
Posts: 22
Joined: Fri Jul 26, 2013 9:43 am
Location: PUNE

Post by nitingupta »

Thanks Ray and Craig for your valuable inputs. I have implemented the logic by creating routine using NUM() and Iconv with MD and its working as expected. :-)
NITIN GUPTA
Post Reply