Usage of Field Function

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
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Usage of Field Function

Post by balajisr »

Is it correct to use field function with delimiter as a string
(e.g Field(string,'ABC DEF',2). and not as a single character?
I have a requirement to find values between two strings so thought of using field function for that.

E.g ABC DEF
This is the value to Extract
VVV EEE

where i need to extract values between ABC DEF and VVV EEE. Since my file is unstructured my record spans multiple lines.So, value to be extracted can also span multiple lines.

I tried to use string as delimiter and it works. Want to know whether it is advisable. Please advise.

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

Post by kcbland »

It's fine.
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
AaronVG
Participant
Posts: 13
Joined: Thu Feb 15, 2007 4:02 pm

Post by AaronVG »

I use Field quite often.

I have source data that looks like this
part1@part2@part3

I use a Transformer to split the one column into three:
Field(in.col1,"@",1)
Field(in.col1,"@",2)
Field(in.col1,"@",3)

And the Transformer does about 5 other conversion and adds in two additional columns as well.
<<<>>>
My opinions are just that.
boxtoby
Premium Member
Premium Member
Posts: 138
Joined: Mon Mar 13, 2006 5:11 pm
Location: UK

Post by boxtoby »

I'm not sure if I undertand correctly, but I think you're using a string like "ABC DEF" as the delimiter of the main string.

If you are, field my not return the results you're expecting. Here's an example:

String = "aaaa123bbbb123ccccc123dddd"
Ans = field(String, "123", 3)

Ans = 23ccccc !!

Notice in the previous example the separator is a single character, ie. "@"

You can solve this problem as follows:

String = "aaaa123bbbb123ccccc123dddd"
NewString = Ereplace(String, "123", "@")
Ans = field(NewString, "@", 3)

Ans = ccccc

HTH
Bob.
Bob Oxtoby
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Post by balajisr »

If the delimiter of the Field function has multiple character it is able to find the correct value but it could not remove all characters in the delimiter while deriving resultant substring output. It removes only the first character from the delimiter and outputs the rest along with the resultant substring. i.e '23ccccc'.

Also, since the file is highly unstructured i do not want to replace multiple character delimiter to single character since the character to be replace may be present in the record already.

I will proceed using Field() function and handle the delimiter coming as part of resultant substring.

Thanks to everyone for your replies.
Post Reply