Function

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
Mark j
Participant
Posts: 20
Joined: Tue Apr 20, 2004 9:26 am

Function

Post by Mark j »

Hi

Is there any function to do following simple task

I have an input : Mark?????Jason i want to make it Mark" "Jason


Thanks
Mark
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Mark - you might want to clarify exactly what you it is you need to do before people go off chasing too many wild geese. :wink:

So... are you saying you have a field with text that can be seperated by any number (or perhaps a fixed number) of question marks or spaces or what? And then you need to turn it into what exactly - something with a single space between it or literally what you posted: a space surrounded by two double-quotes?

If you don't mind me asking, why would you need to do this? It seems like an... "interesting" requirement. :?
-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 »

This is an easy task for DataStage's pattern matching capabilities.

You need to determine what's between "Mark" and "Jason" and then replace this with the three characters '" "' (a double quote, a space and another double quote).

Use the MatchField function to get what's between "Mark" and "Jason".

Code: Select all

Pattern = "0X'Mark'0X'Jason'0X"
Result = MatchField(TheString, Pattern, 3)
Then use the Ereplace function to effect the substitution

Code: Select all

If Result > ""
Then
   NewResult = Ereplace(TheString, Result, '" "', 1, 1)
End
If you want to do the whole thing as a single expression, for example for a column derivation, and you are sure of at least one character between "Mark" and "Jason", simply nest the functions.

Code: Select all

Ereplace(TheString, MatchField(TheString, "0X'Mark'0X'Jason'0X", 3), '" "', 1, 1)
If it's possible that there may be zero characters between "Mark" and "Jason", wrap it in an If .. Then .. Else to test for this possibility.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Or never mind the clarification and wait for Ray to roll you up an all-purpose answer. :lol:
-craig

"You can never have too many knives" -- Logan Nine Fingers
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

Try not to put this type of code directly in your transformer, make it a routine and pass it values. That way you get to use the routine "Test" form to test various input patterns to make sure your logic is correct. You can then play around with lots of different EREPLACE and pattern options and test each one until it is correct, much faster then putting the code into a transformer and running a job to see if it correct.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

... and the Test grid for Routines is a great tool for doing just that! 8)

Folks to whom I teach DataStage classes will recount how I use this technique to help get a feel for the intricacies of Oconv, for example.

Good catch, Vince.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Mark j
Participant
Posts: 20
Joined: Tue Apr 20, 2004 9:26 am

Post by Mark j »

Thanks for your suggestions

I phrased my question wrong:)

if i have more than one space it should be replaced with single space as in following example

Mark jason Oakman then the result should be Mark jason Oakman

you never know for sure how many spaces you have... I hope i am clear enough with my question. :?:

Thanks
Mark
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Use of TRIM(link.column) removes all leading and trailing spaces; and where multiple spaces reduces to one space as long as it's not a leading or trailing space. Check your Online Documentation DS BASIC manual for the TRIM function.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Mark j wrote:Thanks for your suggestions. I phrased my question wrong:)
See, Ray. So how was that goose? :lol:
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply