Regular expressions in Datastage Tranformer
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 10
- Joined: Fri Feb 20, 2004 4:25 am
Regular expressions in Datastage Tranformer
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
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
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:
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
-
- Participant
- Posts: 10
- Joined: Fri Feb 20, 2004 4:25 am
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
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.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact: