Subtraction of values using Stage variables in a transformer

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
js_j
Participant
Posts: 12
Joined: Fri Aug 19, 2011 5:04 am
Location: India

Subtraction of values using Stage variables in a transformer

Post by js_j »

Hi,

My file structure is

EMP NO Hours Type
1001 1 A
1001 2 B
1002 4 A
1002 5 B

My requirement for every occurrence of the employee number 1 the corresponding hours should be subtracted. There are only two occurences for every employee.

O/P should be
EMPNO Hours Type
1001 -1 X
1002 -1 X

I am trying to use a stage variable to do so.
kindly help me out for the same.


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

Post by ray.wurlod »

It's very straightforward. Show us what you've attempted, and explain why it's not producing the expected output.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kiran0435
Participant
Posts: 39
Joined: Sun Sep 26, 2010 10:28 pm

Post by kiran0435 »

Job for this done as follows

Code: Select all


source--- sortstage-- transformer---removeduplicates--- target

In sort stage sort the data based on EMP NO and set Create Key Change column to True.

Then in Transformer use the following derivation in stage variables

stg1-- inputcol.hours

stg2-- if key change column=1 then stg1 else stg1-stg3

stg3-- stg1

Map stg2 to hours column

In the next Remove Duplicates stage retain the last column in the group. Then you wil get the required result.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If you give a man a fish he'll be fed briefly. If you teach a man to fish, he need never be hungry.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
SURA
Premium Member
Premium Member
Posts: 1229
Joined: Sat Jul 14, 2007 5:16 am
Location: Sydney

Post by SURA »

Yes Ray

You are right.

DS User
Post Reply