Search code examples
datastage

compare current value with previous value in datastage


i have input like below

empid salary 10 1000 20 2000 30 3000 40 4000

the output i require in a sequential fie is like below. that is prevsal should have the salary of the previous row

empid salary prevsal 10 1000 null 20 2000 1000 30 3000 2000 40 4000 3000

i tried using a transformer by giving stage variable as prevsal=inputlink.salary and then defining a output column inputlink.salary=prevsal. i know that doesnt work logically and yes it didnt work. can anyone find me a solution for this.


Solution

  • You are on the right way - transformer and stage variables is the way to go. Remember that within the transformer the data is processed top down. This means the first (top most) stage variable is processed first, then the second and so on and finally the data is put on the output links.

    Having you input column: inputlink.salary Assuming two stagevariables: svPrevSalary (top most) and a second one svCurrentSalary

    Try following assingments in the stage variable section:

    1. svCurrentSalary  (=) svPrevSalary
    2. inputlink.salary (=) svCurrentSalary 
    

    Use

    svPrevSalary

    as derivation of the output link / field.

    Please note that the (=) are just the idea you have to specify only svCurrentSalary for the first stage variable.