Removing (,/ -) from the phone column

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

tonystark622
Premium Member
Premium Member
Posts: 483
Joined: Thu Jun 12, 2003 4:47 pm
Location: St. Louis, Missouri USA

Post by tonystark622 »

Thanks, Ray.

You're right, Index() would be faster. I just did a quick look in the Help file and missed it. Agreed with the Equate instead of the variable assignment, too.

With a function like this you want it to be as fast as possible.

Tony
tonystark622
Premium Member
Premium Member
Posts: 483
Joined: Thu Jun 12, 2003 4:47 pm
Location: St. Louis, Missouri USA

Post by tonystark622 »

OK, here's the final version.

Code: Select all

FUNCTION StripChars(Arg1)
  Equate ValidChars to "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%"

  RetValue   = ""

  For i = 1 to Len(Arg1)
    TestChar = Arg1[i,1]
    If Index(ValidChars, TestChar, 1) > 0 Then
      RetValue := TestChar
    End
  Next i

  Ans = RetValue

RETURN(Ans)
I also moved the numbers to the front of the ValidChars string because they should occur more frequently in the data than alpha or other chars.

Tony
rkumar28
Participant
Posts: 43
Joined: Tue Mar 30, 2004 9:39 am

Removing (,/ -) from the phone column

Post by rkumar28 »

Thank you all very much on providing the information. I really appreciate the help and advice and taking out time to help me resolving this issue. Thanks for the routine, it realy made my life little easy.

Thanks
Raj
tomengers
Participant
Posts: 167
Joined: Tue Nov 19, 2002 12:20 pm
Location: Key West

Post by tomengers »

Leslie ...

That's Horseshoes, Handgrenades and Heavy Breathing.

... tom
mandyli
Premium Member
Premium Member
Posts: 898
Joined: Wed May 26, 2004 10:45 pm
Location: Chicago

Removing ,/-)

Post by mandyli »

Hi

I hope this very simpale. in the datastage Trim function is there.
Trim(ur string,",", A) that means remove ", " from ur string or ur fields..

please check it will work now..

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

Post by ray.wurlod »

Not unless you provide an expression or a quoted string as the third argument, for example Trim(string, ",", "A").
However, the Trim function can only remove occurrences of one character, to remove six would require six applications of the Trim function. It is not possible to provide a general solution using the Trim function.
Do become familiar with the other functions. Open up the on-line help from Designer, go to the topic "BASIC Tasks" and from there examine the data conversion and formatting topics, which will introduce you to the most commonly used functions in these categories.
It's always best to choose the right tool for any job; for this job Trim simply isn't the right tool.

(DataStage training can be had in Singapore - find out where by visiting the Ascential web site.)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
nhyatt
Participant
Posts: 1
Joined: Tue Nov 26, 2002 10:15 am
Location: United Kingdom

Post by nhyatt »

I did have a requirement for returning alphanumeric before and the method I used was

Convert(Oconv(Oconv(FieldIn,"MC/A"),"MC/N"),"",FieldIn)

If you did need to keep some non alphanumeric characters you could use

Convert(Convert("#$%","",Oconv(Oconv(FieldIn,"MC/A"),"MC/N")),"",FieldIn)

not sure how this compares with the datastage routine speedwise though.

Regards
Nick
tonystark622
Premium Member
Premium Member
Posts: 483
Joined: Thu Jun 12, 2003 4:47 pm
Location: St. Louis, Missouri USA

Post by tonystark622 »

I haven't waded all the way through it to understand it, Nick, but I tested it and it looks like it does the same thing that my routine does. Cool!

I don't know about speed, but I like it's brevity.

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

Post by ray.wurlod »

:idea: Oconv (and Iconv) can handle a multi-valued list of conversion specifications, which are applied one after another.
So, even more brief:

Code: Select all

Convert(Convert("#$%","",Oconv(FieldIn,"MC/A":@VM:"MC/N"),"",FieldIn) 
This is a good way to generate an SDK timestamp (one with no delimiters).

Code: Select all

Oconv(TheDate, "DYMD[4,2,2]":@VM:"MCN") : " 00:00:00"
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
tonystark622
Premium Member
Premium Member
Posts: 483
Joined: Thu Jun 12, 2003 4:47 pm
Location: St. Louis, Missouri USA

Post by tonystark622 »

Thanks, Ray. I appreciate the tip. I'm sure it also speeds this one up a tiny bit.

Take care,
Tony
Post Reply