How to convert records based on certian contents of records

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
ambasta
Participant
Posts: 93
Joined: Thu Jan 19, 2006 10:29 pm
Location: Bangalore

How to convert records based on certian contents of records

Post by ambasta »

Hi All,
My requirement is to convert the data based on certain conditions.I am explaining the problem using an example.
If data is like 12345$ABC6789 then populate data as 12345A6789
if data is like 12$BCD3456789 the populate data as 12B3456789
if data is like 1234567$CDE89 the populate data as 1234567C89.
these four digits ($ABC,$BCD,$CDE) can be at any position in the source data.
Can anyone of you please help me on this...
Thanks in Advance..
ambasta
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Do this:

Code: Select all

Field(in.Col, "$",1):Field(in.Col,"$",2)[1,1]:Field(CONVERT('ABCDEFGHIJKLMNOPQRSTUVWXYZ','',Upcase(in.Col)),"$",2)
Get everything before the dollar sign, concatenate it to the first character of everything after the $ sign. Then finally get rid of all your alphabets and concatenate everything after the dollar sign. Pretty much what the above code is doing.
NOTE: If there are other characters, excluding $ sign, that will be present along with alphabets, add them to the list in the CONVERT() function.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ambasta
Participant
Posts: 93
Joined: Thu Jan 19, 2006 10:29 pm
Location: Bangalore

Post by ambasta »

DSguru2B wrote:Do this:

Code: Select all

Field(in.Col, "$",1):Field(in.Col,"$",2)[1,1]:Field(CONVERT('ABCDEFGHIJKLMNOPQRSTUVWXYZ','',Upcase(in.Col)),"$",2)
Get everything before the dollar sign, concatenate it to the first character of everything after the $ sign. Then finally get rid of all your alphabets and concatenate everything after the dollar sign. Pretty much what the above code is doing.
NOTE: If there are other characters, excluding $ sign, that will be present along with alphabets, add them to the list in the CONVERT() function.
Thanks a lot for your kind suggession..actually i am not sure why we are taking substring[1,1].Will you be kind enough to explain the logic using any example.Thanks in advance..
ambasta
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Re: How to convert records based on certian contents of reco

Post by DSguru2B »

ambasta wrote: If data is like 12345$ABC6789 then populate data as 12345A6789
if data is like 12$BCD3456789 the populate data as 12B3456789
if data is like 1234567$CDE89 the populate data as 1234567C89.
Look at your final data. It contains the first alphabet right after the $ sign. Thats what the substring is for.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Ambasta, there is no need to quote entire messages when replying.

DSGuru2B's logic is succinct:

Take the whole string before the first $ sign
Append the single character after the first $ sign
Remove alpha characters from the remainder and append.

I might suggest changing that a bit to read

Code: Select all

Field(in.Col, "$",1):Field(in.Col,"$",2)[1,1]:Field(in.Col,"$",2)[4,9999]
since your delimiting string is always 4 chars long.

And for efficiency it might be best to assign a stage variable to the output of Field(in.Col,"$",2).
ambasta
Participant
Posts: 93
Joined: Thu Jan 19, 2006 10:29 pm
Location: Bangalore

Post by ambasta »

All the above example of records is only for single column.how do i write the if-else condition.If data contains $ABC then replace it with A else if data contains $BCD then replace it with B else if data contains $CDE then replace it with C and so on....
ambasta
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You've missed the point. You don't need to treat them separately, because they follow a common pattern, namely nnnnnn$aaaannnnn. As was described - documented - in the response by DSguru2B, the expression takes:
  • everything to the left of the $ character {Field(x, "$", 1, 1)}

    the first character of (everything to the right of the $ character) {Left(Field(x, "$", 2, 1), 1)} - which he gave as Field(x, "$", 2, 1)[1,1]

    then removes all the alphabetic characters from (everything to the right of the $ character) [Convert("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "", Upcase(Field(x, "$", 2, 1))}

    finally concatenating the three intermediate results to form the desired answer
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

I guess my explanation was'nt clear enough. Ray's explanation should put you to rest and answer your doubts.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If you're happy with the explanation, please mark the thread as Resolved. Otherwise please indicate what it is you don't follow.
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