Update the next row depending on the values of previous row

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
dprasanth
Charter Member
Charter Member
Posts: 90
Joined: Fri Oct 07, 2005 7:55 am

Update the next row depending on the values of previous row

Post by dprasanth »

Hi,
I know that this topic has been discussed few times in this forum, but my problem is a bit different.

I have got four columns in my source database
mno Joined_dt cancel_dt memtype
1 05/05/2005 07/08/2005 A
1 05/09/2005 30/12/1899 B
1 10/11/2005 30/12/1899 C
1 10/02/2006 30/12/2006 C
2 05/01/2006 30/12/1899 A
2 05/02/2006 30/12/1899 B
2 05/03/2006 30/12/1899 A

For each memberno , I have do the following, if the cancel_dt is 30/12/1899, then I have to take the next joined_dt for the member and then subtract one from it and put that in the current cancel_dt column or else leave the cancel_dt as it is
Now for the first row of my example, I will not do anything to the cancel_dt as it is a valid date. But the second row has the cancel_dt of 30/12/1899. So I have to go to the third row and check the joined_dt which is 10/11/20005 , subtract one from it, which will be 09/11/20005 and update this value for the second cancel_dt for memno
So now my columns will look like
mno Joined_dt cancel_dt memtype
1 05/05/2005 07/08/2005 A
1 05/09/2005 09/11/2005 B
1 10/11/2005 09/02/2006 C
1 10/02/2006 30/12/2006 C


I used stage variables do achive this but I am not getting the proper results. The stage variable I am using are
Readln.MEMBERNO | key
Key <> Oldkey | changedkey
Readln.MEMBERNO | Oldkey

I tried using the constraint changedkey =0 and 1 with various permutation combination, but not getting the required rows in my target sequential file.

Could anyone of you please mind guiding me whether this can be achieved.

Thanks a ton in advance.

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

Post by ray.wurlod »

Yes it can, and the methods can be found by searching the forum. The technique is to use stage variables to "remember" the values from previous row and to compare the same with the current row.

I think you also need to be doing a similar comparison on MemTyp, based upon your description.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
loveojha2
Participant
Posts: 362
Joined: Thu May 26, 2005 12:59 am

Post by loveojha2 »

Create one more link to the target from the same transformer and send the changed row only after you recieve the new row through this link
and the other link would be sending the row if the row is not to be changed.

Although it is not the exact solution but it should give you the outline of how to proceed with it.
Success consists of getting up just one more time than you fall.
dprasanth
Charter Member
Charter Member
Posts: 90
Joined: Fri Oct 07, 2005 7:55 am

Post by dprasanth »

ray.wurlod wrote:Yes it can, and the methods can be found by searching the forum. The technique is to use stage variables to "remember" the values from previous row and to compare the same with the current row.

I think you also need to be doing a similar comparison on MemTyp, based upon your description.
Thanks Ray.. will try to search the forum properly and will try out what you have told me.
sb_akarmarkar
Participant
Posts: 232
Joined: Fri Sep 30, 2005 4:52 am
Contact:

Post by sb_akarmarkar »

Hi,

One way to store old value in hashfile whenever there is cancel_dt= '30/12/1899' Keep key column value as 1 so alway one row in hash file and use some stage variable to store 1 if last record is cancel_dt= '30/12/1899' else 0 and in constraint keep condition like if 1 then update record take value from hash file and cancel_dt = joined_dt-1 (from new row) and insert else insert only....

I think this will help you.

Thanks,
Anupam
Post Reply