Previous row 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
aramachandra
Participant
Posts: 55
Joined: Tue Sep 20, 2005 10:58 am

Previous row value

Post by aramachandra »

Hi All

I am using the 8.0 version and have the following logic in the transformer to get the previous row value checked to raise unique sequence numbers

Mapping as viewed in transformer


<B>Derivation -------------------------> stage variable</B>

SOURCE COLUMN ------------------------------ > currentvalue

if currentvalue <> previousvalue then ----> mycounter
myycounter=mycounter+1 else mycounter
currentvalue ----------------------------------> previousvalue


But my previous and current columns are identifical when i view them in the next stage

Any ideas what is missing here


arvind
aramachandra
Participant
Posts: 55
Joined: Tue Sep 20, 2005 10:58 am

Post by aramachandra »

The source file is a simple text file with one column

COLUMN1

Test1
Test2
Test3


Arvind
aramachandra
Participant
Posts: 55
Joined: Tue Sep 20, 2005 10:58 am

Post by aramachandra »

Expected output is


1 Test1
2 Test2
3 Test3
aramachandra
Participant
Posts: 55
Joined: Tue Sep 20, 2005 10:58 am

Post by aramachandra »

I reviewed the other post for the similar situation and did not find anything in particular about version 8.

In general my logic is

currentvalue=source column
if previousvalue <> currentvalue then counter= counter+1 else counter
previousvalue=currentvalue

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

Re: Previous row value

Post by chulett »

aramachandra wrote:But my previous and current columns are identifical when i view them in the next stage
Of course, because your last stage variable derivation makes them the same and rightly so:
aramachandra wrote:currentvalue ----------------------------------> previousvalue
Nothing looks obviously wrong to me, what output are you actually getting?
-craig

"You can never have too many knives" -- Logan Nine Fingers
aramachandra
Participant
Posts: 55
Joined: Tue Sep 20, 2005 10:58 am

Post by aramachandra »

My output is

0 Test1
0 Test2
0 Test3
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What do you have for the Initial Value of the counter and previousvalue stage variables? Hopefully something valid for the datatype and not just null/empty.
-craig

"You can never have too many knives" -- Logan Nine Fingers
aramachandra
Participant
Posts: 55
Joined: Tue Sep 20, 2005 10:58 am

Post by aramachandra »

Initial value for the counter is 0
It is type integer

Initial value for the previous value is "none" and it is varchar 25
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Set it to something you know won't ever match on the first comparison, say "?" for example. None means null so your <> check always fails.
-craig

"You can never have too many knives" -- Logan Nine Fingers
aramachandra
Participant
Posts: 55
Joined: Tue Sep 20, 2005 10:58 am

Post by aramachandra »

Thanks it partly worked

As suggested I set the default to "$" for the previousvalue variable and "?" for the currentvalue variable

I added another output column with Y AND N indicator for the change

if PreviousValue <> CurrentValue then 'Y' else 'N'

This above statement seem to be recognizing the previousvalue and evaluating correctly

But then I have a simple statement like

if PreviousValue <> CurrentValue then myCounter = myCounter +1 else myCounter

with myCounter having a default value of 0

That seems to always evaluate to 0
aramachandra
Participant
Posts: 55
Joined: Tue Sep 20, 2005 10:58 am

Post by aramachandra »

Thanks it partly worked

As suggested I set the default to "$" for the previousvalue variable and "?" for the currentvalue variable

I added another output column with Y AND N indicator for the change

if PreviousValue <> CurrentValue then 'Y' else 'N'

This above statement seem to be recognizing the previousvalue and evaluating correctly

But then I have a simple statement like

if PreviousValue <> CurrentValue then myCounter = myCounter +1 else myCounter

with myCounter having a default value of 0

That seems to always evaluate to 0
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

aramachandra wrote:But then I have a simple statement like

if PreviousValue <> CurrentValue then myCounter = myCounter +1 else myCounter
:? How 'like' that is it? Your syntax as posted is invalid if that's literally what you have in the derivation. It should be:

Code: Select all

if PreviousValue <> CurrentValue then myCounter+1 else myCounter
Expressions only, no direct assignments.
-craig

"You can never have too many knives" -- Logan Nine Fingers
aramachandra
Participant
Posts: 55
Joined: Tue Sep 20, 2005 10:58 am

Post by aramachandra »

Thanks a lot and I am sure you had a laugh at the rudimentary mistake.

Nonetheless I greatly appreciate the help and we can consider this post closed and it worked

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

Post by chulett »

No laughing here, just a learning opportunity. Sometimes it's hard to tell if something is wrong or right when someone says "I have something like this" in a job, your first inkling is to give them the benefit of the doubt and assume they've really got it correct. However, if we dig deeper and things still don't work we revisit those assumptions. :wink:

Glad you got it sorted out, please officially mark the post as Resolved - there's a button at the top of the screen for that.
-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 »

I slept through most all of that!

(Time zone, not boredom. Excellent that it was systematically resolved.)
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