Regular expressions in Datastage Tranformer

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
guidomarcel1
Participant
Posts: 10
Joined: Fri Feb 20, 2004 4:25 am

Regular expressions in Datastage Tranformer

Post by guidomarcel1 »

Hi,
I have the following situation:

I selected records from a table. The record contains a field called option_string which may contain 0-n time a 4byte option.

This means the field option_string may look like this:
471 DC12AS21RT 65T5FGV3
or like this:
LK12L23 DE3 SW2 AQ1 FR4 DE34RF45

Now, I have to separate the 4-byte options by a comma, so that it will look like this:
471 ,DC12,AS21,RT 6,5T5F,GV3
or like this:
LK12,L23 ,DE3 ,SW2 ,AQ1 ,FR4 ,DE34,RF45

Any way to do this via regular expression in Datastage transformer?
Thanks
GuidoMarcel
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

None of the builtin formatting options or other string function can do this in 1 line as would be necessary for a derivation in a transform stage.

I would put in a very short Routine that does:

Code: Select all

Routine MyRoutine(InString)
   Ans = ''
   StringLen = LEN(InString)
   FOR Index = 1 TO StringLen STEP 4
      Ans := InString[Index,4]:','  
   NEXT Index
   Ans = Ans[1,LEN(Ans)-1] ;** strip out last character
guidomarcel1
Participant
Posts: 10
Joined: Fri Feb 20, 2004 4:25 am

Post by guidomarcel1 »

Hi,
thank you very much. Knowing that it is not possible with the built-in functions is already of great help. My compan has no premium account. So, I can not read the rest of your answer. I will try myself!

Thx!
GuidoMarcel
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Guido,

I have marked the post a non-premium so that you can take a look at a simple solution.
guidomarcel1
Participant
Posts: 10
Joined: Fri Feb 20, 2004 4:25 am

Post by guidomarcel1 »

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

Post by ray.wurlod »

The Fold() function will separate the string into four-character pieces separate by @FM characters, a Convert() function will do the rest.

Code: Select all

Convert(@FM, ",", Fold(InLink.TheColumn, 4))
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
guidomarcel1
Participant
Posts: 10
Joined: Fri Feb 20, 2004 4:25 am

Post by guidomarcel1 »

also thanks! :D
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Ray - thanks for that. I went through the list of functions since I had a nagging memory that something like that existed and I couldn't find it; then I checked the formatting of ICONV/OCONV in case the function was hidden in there. I'm glad you remembered that one, since the one-liner without a routine call is much more efficient.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You'll have to stop drinking that English beer! :lol:
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