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
dodda
Premium Member
Premium Member
Posts: 244
Joined: Tue May 29, 2007 11:31 am

Field function

Post by dodda »

Hello

I have a requirement where i have a string like

A%%%AB%%%DF%%%CE%%%XE%%%AF

i want to get the each string which is delimited by %%%.

I used Field function but it is not giving me the required result.

below are the expecte dresults


Field (InputString,'%%%',1)=A
Field (InputString,'%%%',2)=AB
Field (InputString,'%%%',3)=DF
Field (InputString,'%%%',4)=CE
........
Field (InputString,'%%%',6)=AF

Please help me out

Thanks
nani0907
Participant
Posts: 155
Joined: Wed Apr 18, 2007 10:30 am

Post by nani0907 »

hello,

could you please elaborate on how you need data with both input and output.
thanks n regards
nani
dodda
Premium Member
Premium Member
Posts: 244
Joined: Tue May 29, 2007 11:31 am

Post by dodda »

hello nani

i will be getting a string i.e A%%%AB%%%DF%%%CE%%%XE%%%AF in of the fields from the input sequrntial File. I need to read that string and get the values which ar edelimited by %%%

i.e InputString=A%%%AB%%%DF%%%CE%%%XE%%%AF
outstring1=A
outstiring2=AB
outstiring3=DF
outstiring4=CE
outstiring5=XE
outstiring6=AF


I tried field function its not working. please help me
Thanks
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

The documentation of field function says:
delimiter evaluates to any character, including field mark, value mark, and subvalue marks. It delimits the start and end of the substring. If delimiter evaluates to more than one character, only the first character is used.
Hence it seems like your logic will not work in this case.

If '%' will not be present in data itself you can use field function after the followin conversion:

Code: Select all

Trim(DSLink.InputColumn,"%","R")
which will replace %%% with %, then your logic will work.


If '%' can be present in data itself you need to replace '%%%' with some strange characters like fieldmarks,value marks, char(10) or something similar. then you need to apply field function.

You may need to use PXEreplace posted by DSGuru2B quite a while ago to do the same.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

The Field() delimiter must be a single character. So either convert all of the occurances of "%%%" down to a single "%" or offset the "field" that you ask for:

Code: Select all

FieldNumber = PositionNumber * 3 - 2
In other words, 1 gets field 1, 2 gets field 4, 3 gets field 7, etc.
-craig

"You can never have too many knives" -- Logan Nine Fingers
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Replacing %%% with % is on the right track but I would replace with something other than % like char(254).
Mamu Kim
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Sure, you could replace it with pretty much anything as long as you can guarantee that it isn't used anywhere in the data. Hence Kim's choice. That or just use my fancy pantsy formula. :wink:
-craig

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