Getting Next row value and cumulative value for all i/p recs

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
saikirang
Participant
Posts: 6
Joined: Mon Oct 29, 2012 4:26 pm

Getting Next row value and cumulative value for all i/p recs

Post by saikirang »

Could you please help me out on this.

Input -
employee_id, salary
-------------------
10, 1000
20, 2000
30, 3000
40, 5000

1) Create a job to get the next row salary for the current row. If there is no next row for the current row, then the next row salary should be displayed as null.

The output should look like as

employee_id, salary, next_row_salary
------------------------------------
10, 1000, 2000
20, 2000, 3000
30, 3000, 5000
40, 5000, Null


2) Create a job to find the sum of salaries of all employees and this sum should repeat for all the rows.

The output should look like as

employee_id, salary, salary_sum
-------------------------------
10, 1000, 11000
20, 2000, 11000
30, 3000, 11000
40, 5000, 11000
ray.wurlod
Participant
Posts: 54595
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

1) Sort data in reverse order and use stage variables in Transformer stage to "remember" previous row value. If necessary re-sort after Transformer stage.

2) This is a classic 'fork join' design. Use a Copy stage to split your data stream into two. One stream runs through an Aggregator stage to perform the sum. Downstream of that join the two streams together using a dummy constant key generated upstream of the Copy stage (for example using Column Generator stage with a cycle containing one value).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
saikirang
Participant
Posts: 6
Joined: Mon Oct 29, 2012 4:26 pm

Post by saikirang »

Thanks Ray for your quick response ..

Could some one please paste the reply given by Ray as I'm not yet a premium member ... thank you so much!!
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Sorry but that's not the way it works around here and if anyone does I'll just delete it.

How about this? Tell us what you've tried so far and what issues you've faced. Failing that, ideas you've had on how to approach this. That rather than simply coming here and pasting in nothing more than the requirements you've been given to develop two jobs.
-craig

"You can never have too many knives" -- Logan Nine Fingers
saikirang
Participant
Posts: 6
Joined: Mon Oct 29, 2012 4:26 pm

Post by saikirang »

Craig - I did try few options which I thought were not best methods / optimal solutions to achieve it. hence, I asked for some suggestions .... Thanks for your feedback ... henceforth, i will post my approaches as well...

I tried another option which worked well. I used 'transformer' looping options to achieve this using "SaveInputRecord() & GetSavedInputRecord()" functions.

It would be great if you could let me know what Ray mentioned in the previous post ... Thanks again!!
Post Reply