help in logic

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
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

help in logic

Post by pandeesh »

Hi,
My source sequential file contains 4 fields:

Code: Select all

id,division,date,amount
--------------------------
1,0,10-10-2011,1
1,0,11-10-2011,12
1,0,12-10-2011,23
1,1,1-1-2011,12
1,1,2-1-2011,13
My expected output should be like below:

Code: Select all

id,division,date,amount,amount1
-------------------------------------
1,0,10-10-2011,1,1
1,0,11-10-2011,12,13
1,0,12-10-2011,23,36
1,1,1-1-2011,12,12
1,1,2-1-2011,13,25
I have achieved this using the below design:

Code: Select all

seqfile------linksort on id,division and date--->Sortstage(id,division)-->xfm-->xfm1--->tgt_dataset
i am using two transformer stages. In the first transformer, i am introducing the column amount1 with amount values for the first record in each group.
For the first record in each group the amount1 will be same as amount field.
The remaining records will have 0 in amount1.

in the second transformer, i am calculating the amount1 using stage variables.

Is it possible to achieve the same using a single transformer stage

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

Post by ray.wurlod »

Use stage variables (and maybe a Sort stage generating key change column sorting on id and division). Increment counter if no change, reset counter if there is a change.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

in my design, i am using 2 transformers xfm and xfm1.In XFM, i am adding a new column Amount1 with below values:

1)In each group ,for the first record (whose Keychangecolumn is 1), i am populating amount value as it is to amount1.

2)For the remaining records in the group i am setting 0.

In xfm1(2nd transformer stage),i am summing up amount1 with amount as per the requirement,
The stage variables i am using are:

Code: Select all


StageVar=Amount1
StageVar1=if keychangecolumn=1 then StageVar else StageVar2+Amount
StageVar2=StageVar1

And passing StageVar1 to Amount1 field.
i am able to get the desired output.But i am using 2 transformer stages(xfm,xfm1).

Is there any other way to achieve this using a single transformer?

Thanks
pandeeswaran
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I don't see anything about this that requires two transformers. It's just a running subtotal and you can do all that in one transformer along with the 'group change detection' you are doing.
-craig

"You can never have too many knives" -- Logan Nine Fingers
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

My understanding is:

1)The input to the first transformer doesn't have amount1 fields .it has only amount field only.

2)In the transformer i can hold the value of the previous input record. i can hold the previous value of amount but not amount1,

As per my requirement, i need to add the Previous value of amount1 with current value of amount.

i dont know how to maintain the summed up values of amount(in stead of considering amount1) in stage variable.

Please help me.

Thanks
pandeeswaran
kamtammystuff
Participant
Posts: 26
Joined: Fri Feb 19, 2010 2:08 am

Post by kamtammystuff »

I see your problem here, U can use the same logic you mentiuoned in a single transformer and before that you need to initialze the StageVar variable to 0. So that for the very first record you will have 0 + Amount and then subsequently you'll be able to add Amount to StageVar1.
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

I will try that:

Code: Select all

StageVar1=if keychange=1 then amount else amount+StageVar2
StageVar2=StageVar1

Initial Value:
StageVar1=0
Last edited by pandeesh on Thu Nov 24, 2011 11:55 pm, edited 1 time in total.
pandeeswaran
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

kamtammystuff wrote: U can use the same logic ...
... but do you think U (one of our posters) would actually need to?

The second person personal pronoun in English is spelled "you", not "u".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Every If needs a Then (as well as an Else) in DataStage expressions.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

Edited the expression with then clause
pandeeswaran
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

And?
-craig

"You can never have too many knives" -- Logan Nine Fingers
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

It's working fine
pandeeswaran
Post Reply