Previous Record Values

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
c341
Participant
Posts: 39
Joined: Mon Jan 26, 2004 8:43 pm

Previous Record Values

Post by c341 »

Hi
I need to know how to get the previously processed records value.
In transformer I have condition ...Current value - Previous value.
Thank You
Regards - c341
rasi
Participant
Posts: 464
Joined: Fri Oct 25, 2002 1:33 am
Location: Australia, Sydney

Post by rasi »

Hi

You have set of routines under sdk/RowProc folder.

In that you can use RowProcGetPreviousValue to get the previous value for that column. Also you can do a compare using RowProcCompareWithPreviousValue.

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

Post by ray.wurlod »

You can use a pair of stage variables, and rely on the fact that stage variables are processed in the order in which they are defined in their grid.
Techniques have been posted before, search them out. Quick example:

Code: Select all

svIsChanged    If (InLink.ColName<> svPrevValue) Then 1 Else 0
svPrevValue    InLink.ColName
In this example, when stage variable svIsChanged is being evaluated, stage variable svPrevValue still contains the value of InLink.ColName from the previous row.
A more appropriate derivation for svIsChanged is

Code: Select all

If (InLink.ColName <> svPrevValue)  And (@INROWNUM <> 1) Then 1 Else 0
or, more simply

Code: Select all

InLink.ColName <> svPrevValue And @INROWNUM <> 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.
dsxdev
Participant
Posts: 92
Joined: Mon Sep 20, 2004 8:37 am

Post by dsxdev »

Rigthly said you can use Stage variables to hold prevoius record's value and use it in current record. Stage variable are caluculated in the order they are defined.If you set default value for a stage variable you avoid teh @INROWNUM also

Code: Select all

If (InLink.ColName <> svPrevValue) Then 1 Else 0
Happy DataStaging
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You need to be totally sure that any initial value that you assign to a stage variable will never, ever appear in data. Including @INROWNUM <> 1 is a mechanism that I call "idiot proofing".
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