Page 1 of 1

Reading file and updating the previous row

Posted: Mon Oct 30, 2006 2:18 am
by neeraj
Need help. I have to read row by row and update the previous row based on the value of next row.

Here is the data.

99,"997 ",20030101,20081231,
99,"997 ",20030201,20081231,
99,"997 ",20030401,20081231,

The result should be
99,"162 ",20030101,20030201,
99,"162 ",20030201,20030401,
99,"162 ",20030401,20081231,

Posted: Mon Oct 30, 2006 5:29 am
by Kirtikumar
You can use the stage variables to preserve the value of the previous row.

Define two stagevars - first is set to second stage var and second stage var set to direct mapping from column for which you want to preserve the prev value.
Initialise them to empty.

When this runs for the first time, in the output column mappings for column where u want the prev value, check if stage var1 is empty, then assign the incoming column, else to the stage var1.

Make sure order of the stage var is proper i.e. first stage var has direct column and second has been assigned to the first stage var.

When it runs for the first row. First stage var will be empty as stage var2 is empty. stage var2 will get the value 20030201. When u map the output col due to the derivation on that column(if stage var1 is empty, then assign the incoming column, else to the stage var1), will set it to 20030201. Next time first stage var will be 20030201 and second will be 20030201. Now the value of the prev row which is there in the first stage var will go on the output.

HTH