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..
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
Can We calculate the no. of Alpha Char. in a string
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
This expression is true for a valid string and false for a string containing any invalid character.
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
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Re: Can We calculate the no. of Alpha Char. in a string
I think this can be better done via scripting rather than Datastage. You can use anything that supports regular expressions and do this.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..
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
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.
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.
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
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.
my post could have been phrased better(relative ) and don't make me an anti-Datastage terrorist
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.