Reading file and updating the 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
neeraj
Participant
Posts: 107
Joined: Tue May 24, 2005 4:09 am

Reading file and updating the previous row

Post 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,
Kirtikumar
Participant
Posts: 437
Joined: Fri Oct 15, 2004 6:13 am
Location: Pune, India

Post 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
Regards,
S. Kirtikumar.
Post Reply