Can We calculate the no. of Alpha Char. in a string

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
ajmore
Participant
Posts: 22
Joined: Fri Aug 25, 2006 5:25 am

Can We calculate the no. of Alpha Char. in a string

Post by ajmore »

Hi All :D ,

I have to do a validation on a Varchar field as follows....

1) First Char must be Alpha---i got this using function Alpha(Left(inxfmLoadData1.DFSNAM,1)) = 1

2) Valid char.. r Alphabets,Blanks,Hypens and Apostrophes...

3) Blanks,Hypens and Apostrophes must not be adjacent

Can anybody Help me in this issue..

:idea: Also Please provide me the method to Calculate the no. of Alphabets in a String in Transformer i will then move fwd with some logic...

Thanks in Advance
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You don't need to count them to validate that only the appropriate types are in the string.

Alpha() will work on the entire string, returning 1 if every character in the string is alphabetic.

The easiest way to test for a set of valid characters is to convert them all to "" then test the length of the remainder.

Code: Select all

Len(Convert("ABCDEFGHIJKLMNOPQRSTUVWXYZ -'abcdefghijklmnopqrstuvwxyz", "", InLink.TheString)) = 0
This expression is true for a valid string and false for a string containing any invalid character.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ajith
Participant
Posts: 86
Joined: Thu Nov 10, 2005 11:10 pm

Re: Can We calculate the no. of Alpha Char. in a string

Post by ajith »

ajmore wrote:Hi All :D ,

I have to do a validation on a Varchar field as follows....

1) First Char must be Alpha---i got this using function Alpha(Left(inxfmLoadData1.DFSNAM,1)) = 1

2) Valid char.. r Alphabets,Blanks,Hypens and Apostrophes...

3) Blanks,Hypens and Apostrophes must not be adjacent

Can anybody Help me in this issue..

:idea: Also Please provide me the method to Calculate the no. of Alphabets in a String in Transformer i will then move fwd with some logic...

Thanks in Advance
I think this can be better done via scripting rather than Datastage. You can use anything that supports regular expressions and do this.

All of your requirements are related to string manipulation, and there are no extensive support for string manipulation in datastage other than the basic ones. So I think It would better be done outside datastage than inside it. It is only a suggestion

Thanks,
Ajith
Last edited by ajith on Wed Dec 13, 2006 8:57 am, edited 1 time in total.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Actually, I'd say the support for string manipulation in DataStage is very extensive. 'Better' is a relative word, so perhaps in some instances in some shops there are 'better' ways to do it, but I prefer to stay in the tool if at all possible... and I don't recall the last time that wasn't possible. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
ajith
Participant
Posts: 86
Joined: Thu Nov 10, 2005 11:10 pm

Post by ajith »

chulett wrote:Actually, I'd say the support for string manipulation in DataStage is very extensive. 'Better' is a relative word, so perhaps in some instances in some shops there are 'better' ways to do it, but I prefer to stay in the tool if at all possible... and I don't recall the last time that wasn't possible. :wink:
:oops:

my post could have been phrased better(relative :roll: ) and don't make me an anti-Datastage terrorist :cry: :cry:
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

:lol: No worries. I'll call the FBI back and tell them "never mind".
-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 »

My earlier post did not address your third requirement, that legal non-alphabetic characters must not be adjacent.

This one is not possible using out-of-the-box functions, since you need to loop through each adjacent pair of characters. You will need to create either a parallel routine (external C++ code) or a BuildOp stage (internal C++ code) to achieve this result.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply