Looping Using Stage Variable

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
sjordery
Premium Member
Premium Member
Posts: 202
Joined: Thu Jun 08, 2006 5:58 am

Looping Using Stage Variable

Post by sjordery »

I have a requirement like this:

The input file has one column called code whose value is 7878D0990.
In that I need to search from backward and get the alphabet found i.e D.
The value changes in every run.

I am thinking to use stage variables but not sure how to perform looping using stage variables.
Any help will be appreciated.

Thanks in advance.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Given that you've marked this as a server job:

Code: Select all

MatchField(InLink.Code, "0N1A0N", 2)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sjordery
Premium Member
Premium Member
Posts: 202
Joined: Thu Jun 08, 2006 5:58 am

Post by sjordery »

Thanks Ray.
This is working if one string is there before the numbers from back word.
for e.g if the string is 5656D09 then MatchField("5656D09", "0N1A0N", 2)is returning the correct vale D.

But ,if the string is 5656ID09 then MatchField("5656ID09", "0N1A0N", 2)is returning null where result should be D?
Any sugesstions?

Thanks,
SJ.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I don't see how 'matches' can get you the last occurance, at least not easily. Perhaps Ray knows some magic for that. :?

Me, I would build a routine that does the 'looping' you asked about. Check the length of the string, execute a For loop stepping from that to 1 step -1, use substring at that position to check for Alpha() and exit the first time time returns true.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Code: Select all

Right(MatchField(InLink.Code, "0N0A0N", 2), 1)
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