Searching a string in a set of strings

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
parag.s.27
Participant
Posts: 221
Joined: Fri Feb 17, 2006 3:38 am
Location: India
Contact:

Searching a string in a set of strings

Post by parag.s.27 »

Hi all,

I need to check the incomming source data string of a column, for words like ELEC, GAS, & CONS.

The data is comming as ABC ELECTRICALS, Cooper GAS works, etc.

currently i am using

Code: Select all

VarIndex = index('ABC ELECTRICALS','ELEC',1)
If VarIndex <> 0 then Ans = 1 else Ans = 0.
, but for above mentioned 3 to 4 types its becomming cumbersome to use this function in my routine,

can anyone please tell me that is there any function like substring or something else to do it in a single line
Thanks & Regards
Parag Saundattikar
Certified for Infosphere DataStage v8.0
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Unfortunately if you wish to use INDEX() you will need to do some sort of a loop, checking the string for each substring in your list sequentially.

The DataStage pattern matching mechanism will work for you here, though. You can use an expression such as

Code: Select all

In.Column MATCHES "0x'ELEC'0x":@VM:"0x'GAS'0x"
to separate the different search strings with the @VM to get multiple searches, the results are OR'd together so it will return a TRUE (1) if any one of the searches match the pattern.
parag.s.27
Participant
Posts: 221
Joined: Fri Feb 17, 2006 3:38 am
Location: India
Contact:

Post by parag.s.27 »

ArndW wrote:Unfortunately if you wish to use INDEX() you will need to do some sort of a loop, checking the string for each substring in your list sequentially.

The DataStage pattern matching mechanism will wo ...
Hi Arnd,

What you are saying is my concern, that's why i am seeking any single line function. Sorry but, i was not able to see your post entirely

can you help me with it

thanks
Thanks & Regards
Parag Saundattikar
Certified for Infosphere DataStage v8.0
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

parag.s.27,

this is a premium post; it gives information that is more detailed than normal and is meant for those who are serious enough about their work and use of the DSXchange forum to join and pay the annual membership. I have unmarked the post as "premium" to let you see what you did miss the first time around and perhaps you will change your mind and decide to join and become a premium member.
Sunshine2323
Charter Member
Charter Member
Posts: 130
Joined: Mon Sep 06, 2004 3:05 am
Location: Dubai,UAE

Post by Sunshine2323 »

if (index(Arg1,'ELEC',1)+ index(Arg1,'GAS',1)+index(Arg1,'CONS',1))>0 then 1 else 0
Warm Regards,
Amruta Bandekar

<b>If A equals success, then the formula is: A = X + Y + Z, X is work. Y is play. Z is keep your mouth shut. </b>
--Albert Einstein
parag.s.27
Participant
Posts: 221
Joined: Fri Feb 17, 2006 3:38 am
Location: India
Contact:

Post by parag.s.27 »

Hi all,

Thanks for the help, now i got many possibilities to write a routine effectively
Thanks & Regards
Parag Saundattikar
Certified for Infosphere DataStage v8.0
Post Reply