Key Change - Increment Value

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
Raftsman
Premium Member
Premium Member
Posts: 335
Joined: Thu May 26, 2005 8:56 am
Location: Ottawa, Canada

Key Change - Increment Value

Post by Raftsman »

I am trying to code the following logic in DataStage Transformer;

Field A Field B Value
1 A 1
1 A 2
1 A 3
1 B 1
1 B 2
2 C 1
2 C 2

As you see once the key value changes, I recommence the value. I tried writing an if then else but I believe that there must be a more efficient way. Isn't there a system value that will flag me when a change happens. If not, how can I set the previous value equal to the record just read.

Thanks
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

There is. Assuming that the fields, Field A and Field B are incoming, and based on those, you are trying to set the value.

Then, you can use 'Stage Variables' or 'RowProcCompareWithPreviousValue' routine to achieve that.

Search on RowProcCompareWithPreviousValue to learn how to use it.

HTH,
Whale.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Concatenate the first two columns, store it in a stored procedure, check with incoming, if its same, increment the counter else reset to 1. Search this forum, this has been covered gazillions of times.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

DSguru2B wrote: store it in a stored procedure,
I'm :? . The OP did not specify that the data is being extracted from a db table. I guess you assumed. Hope it's right. :wink: Or did I miss something?

Whale.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
Raftsman
Premium Member
Premium Member
Posts: 335
Joined: Thu May 26, 2005 8:56 am
Location: Ottawa, Canada

Post by Raftsman »

Thanks, I am extracting from a DB2 table. I searched more posts and used a previous solution. Stage variable did the trick.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

I_Server_Whale wrote:
DSguru2B wrote: store it in a stored procedure,
I'm :? . The OP did not specify that the data is being extracted from a db table. I guess you assumed. Hope it's right. :wink: Or did I miss something?

Whale.
What a bummer. I meant stage variable. I was thinking of stored procedure while i was typing out my reply and hence my blunder. :oops:
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
TonyInFrance
Premium Member
Premium Member
Posts: 288
Joined: Tue May 27, 2008 3:42 am
Location: Luxembourg

Post by TonyInFrance »

I_Server_Whale wrote:There is. Assuming that the fields, Field A and Field B are incoming, and based on those, you are trying to set the value.

Then, you can use 'Stage Variables' or 'RowProcCompareWithPreviousValue' routine to achieve that.

Search on RowProcCompareWithPreviousValue to learn how to use it.

HTH,
Whale.
Does the function RowProcCompareWithPreviousValue work in PX?
in my transformer stage I can't seem to find it as I can on a server job.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

No, RowProcCompareWithPreviousValue is a server-based SDK routine and will not work in PX.
TonyInFrance
Premium Member
Premium Member
Posts: 288
Joined: Tue May 27, 2008 3:42 am
Location: Luxembourg

Post by TonyInFrance »

ArndW wrote:No, RowProcCompareWithPreviousValue is a server-based SDK routine and will not work in PX. ...
Thank you; is there any way to compare previous values in PX? Any alternative function? I need to achieve the same result. I'm hoping there's a way.

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

Post by chulett »

As noted above, just use stage variables.
-craig

"You can never have too many knives" -- Logan Nine Fingers
TonyInFrance
Premium Member
Premium Member
Posts: 288
Joined: Tue May 27, 2008 3:42 am
Location: Luxembourg

Post by TonyInFrance »

Folks,

I'm confused as to how I can use stage variables for this problem. Taking the example cited above:
Field A Field B Value
1 A 1
1 A 2
1 A 3
1 B 1
1 B 2
2 C 1
2 C 2

If I define a stage variable (type Varchar 255) to store the concatenated result of Filed A and Field B and another one (type Binary) to detect if in the incoming row the same concatenation is different from the value stored earlier I don't think this would be possible. This would be because for each incoming row the stage variable would be redefined with the concatenated value of Field A and Field B.

Fyi. I have as source a dataset and thus not table.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

svarChanged = IF svarLastFieldB = In.FieldB THEN 0 ELSE 1
svarLastFieldB = In.FieldB
svarCounter = IF svarChanged THEN svarCounter = 1 ELSE svarCounter = svarCounter + 1



Derivation of Out.Value = svarCounter
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

We all have days like that...

Post by ray.wurlod »

svarChanged <== IF svarLastFieldB = In.FieldB THEN 0 ELSE 1
svarLastFieldB <== In.FieldB
svarCounter <== IF svarChanged THEN 1 ELSE svarCounter + 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.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Thanks for that.
Post Reply