Need to Perform Logic in Transformer

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

DS_MJ
Participant
Posts: 157
Joined: Wed Feb 02, 2005 10:00 am

Need to Perform Logic in Transformer

Post by DS_MJ »

Hello:

Need to Perform the following logic in Transformer:

If NOT SUBSTR(MNO,1,1) BETWEEN ''0'' AND ''9''
AND NOT SUBSTR(MNO,2,1) BETWEEN ''0'' AND ''9''
AND NOT SUBSTR(MNO,3,1) BETWEEN ''0'' AND ''9''
THEN SUBSTR(MNO,1,3)
WHEN NOT SUBSTR(MNO,1,1) BETWEEN ''0'' AND ''9''
AND NOT SUBSTR(MNO,2,1) BETWEEN ''0'' AND ''9''
THEN SUBSTR(MNO,1,2)
WHEN NOT SUBSTR(MNO,1,1) BETWEEN ''0'' AND ''9''
THEN SUBSTR(MNO,1,1)
ELSE '' ''
END

I thought of creating a stage Variable and then call this Stage variable int he transformer.

But how do I do the above using If then Else and Field function?

Thanks.
MJ
Thanks in advance,
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

First of all, what have you tried and what is the problem you are facing?
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
DS_MJ
Participant
Posts: 157
Joined: Wed Feb 02, 2005 10:00 am

Post by DS_MJ »

I was thinking to put this in stage variable and use the Field/Index function... but how to go about doing it is the question.
Could use someguidence on how to convert the above logic in Datastage.

Thanks
Last edited by DS_MJ on Wed May 29, 2013 2:23 pm, edited 1 time in total.
Thanks in advance,
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You haven't posted anything to show you could use the Field() function here. Is your source any kind of delimited string? If not then you'll need to stick to substring.
-craig

"You can never have too many knives" -- Logan Nine Fingers
DS_MJ
Participant
Posts: 157
Joined: Wed Feb 02, 2005 10:00 am

Post by DS_MJ »

Oh Sorry.

This field MNO is a VARCHAR of length 15 and has no delimiters in it. It is a combination of Characters and Numbers.
So if the first 3 fields are Character then we need to extract it to create a Prefix.
Need to select Positions that are not Numeric. If all positions are numeric the Prefix will be spaces.
This field - MNO contains many different formats. Each position must be evaluated individually hence the above query.

My Source is a dataset. I will use the transform to process this and other conversion and put it into a dataset.

DATASET -------> TRANSFORM ----------> DATASET
Last edited by DS_MJ on Wed May 29, 2013 2:36 pm, edited 1 time in total.
Thanks in advance,
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

if = if
between = ">=" and "<="
case when = nested if then else
substring = []
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
DS_MJ
Participant
Posts: 157
Joined: Wed Feb 02, 2005 10:00 am

Post by DS_MJ »

Appreciate your quick response.
However, can you please help write it.

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

Post by ray.wurlod »

Code: Select all

If IsValidInteger(Left(InLink.MNO,3)) Then Left(InLink.MNO,3) Else If IsValidInteger(Left(InLink.MNO,2)) Then Left(InLink.MNO,2) Else If IsValidInteger(Left(InLink.MNO,1)) Then Left(InLink.MNO,1) Else ""
There is no solution involving the Field() function.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DS_MJ
Participant
Posts: 157
Joined: Wed Feb 02, 2005 10:00 am

Post by DS_MJ »

Thank you Ray.
I am using 8.7
However, I dont see the function under Type conversion as "IsValidInteger"
Currently I am getting IsValidInteger is not defined.

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

Post by ray.wurlod »

Sorry, that's a local modification here. You can use IsValidDecimal() in the same way.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

I think the solution will return valid number values, however the requirement is to check if it is not number.

Try this

Code: Select all

if len(convert('0123456789','', left (MNO, 3))) =0 then " " else convert('0123456789','', left (MNO, 3))
Also you can use convert('0123456789','', left (MNO, 3)) in a stage variable.

PS: This is not my idea as I did not go through the entire logic, my bad, some one already replied to your mail on ittoolbox group. It was not visible correctly as quote was showing as " hence I mentioned it here. I think this code will work just fine.
Last edited by priyadarshikunal on Fri May 31, 2013 6:29 am, edited 1 time in total.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

priyadarshikunal wrote:the requirement is to check if it is not number.
No it isn't. Read the original post again.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

This is what the OP wrote in a third post.
DS_MJ wrote:So if the first 3 fields are Character then we need to extract it to create a Prefix.
Need to select Positions that are not Numeric. If all positions are numeric the Prefix will be spaces.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

Along with that there are too many NOT's in the query to make sure its not number. Unless I missed something which you noticed. Please enlighten in that case.
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 »

Lagomorph bifurcation.

:wink:
-craig

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