Page 1 of 1

How to set the stage variable within a routine?

Posted: Mon Feb 02, 2004 10:51 am
by aravindk
How can I refer to a stage variable within a routine? What I am trying to do is set a stage variable based on certain conditions tested on the input columns.

Posted: Mon Feb 02, 2004 11:30 am
by chulett
You don't set one in a routine. If you need to refer to it in a routine, pass it in as one of the arguments. You sould be able to set the Stage variable by simply testing for your 'certain conditions' in the derivation and then set the value based on the outcome of those tests in much the same fashion that you would for any other field coming out of a Transform.

Posted: Mon Feb 02, 2004 12:22 pm
by aravindk
This is what I am trying to achieve

If InField1 = 0 then
StageVar = KeyMgtGetNextValue AND OutField1 = StageVar
Else
OutField1 = StageVar

This topic was recently discussed in
viewtopic.php?t=86271

wherein it was suggested that a function can be written to update the stage variable. That is exactly what I am trying to do.

Sorry for not being clearer the first time.

Posted: Mon Feb 02, 2004 12:48 pm
by raju_chvr
Did u try using the same if...then..else in the column derivation within Transformer, instead of a Routine ?

Posted: Mon Feb 02, 2004 12:58 pm
by aravindk
Yes I did. While it doesnt return any error, it doesnt give the required output.

Posted: Mon Feb 02, 2004 1:20 pm
by chulett
Why not just use your basic derivation for the Stage variable itself and then always populate Outfield1 with the Stage variable? Use:

Code: Select all

If InField1 = 0 then KeyMgtGetNextValue Else StageVar
in the derivation of the StageVar, and then drag it down to the derivation of the Outfield1 column.

Posted: Mon Feb 02, 2004 2:23 pm
by raju_chvr
there u go .. U have a very elegant solution !

Posted: Mon Feb 02, 2004 2:33 pm
by aravindk
Worked like Charm! elegant solution indeed....

Thanks to both of you!

Posted: Mon Feb 02, 2004 4:31 pm
by aravindk
That elegant solution is really spoiling me... I am back here again looking for help.

Expanding the previous problem, *before* incrementing the stage variable, I want to save the the current value of the stage variable into another stage variable. Is this possible?

e.g. I have one stage variable, lets say stagevar1 of which the derivation is

stagevar1 = (if infield1 = 0 then KeyMgtNextValue else infield1 )

Now I want to use another, which is stagevar2 which should hold the value before updating the field,

stagevar2 = stagevar1

I want this assignment happen before the derivation for stagevar2 happens. I declared the stagevar2 before stagevar1, but didnt help.

TIA,

Posted: Mon Feb 02, 2004 4:59 pm
by chulett
It sounds like it should have worked just fine as the Stage Variables are evaluated in order from top to bottom. It is a very common methodology to do exactly the kind of thing you are doing to check for changes, like changing groups in ordered data for instance.

An issue might be what you put for the initial values when you declared both of them. What happens on the very first row, what is the 'old' value of Stagevar1 that is being put into Stagevar2?

Posted: Mon Feb 02, 2004 5:07 pm
by aravindk
In my case, both StageVar1 and StageVar2 are same, giving me the impression that it assigns StageVar2 *after* deriving StageVar1.

Posted: Mon Feb 02, 2004 5:16 pm
by aravindk
Oops.. It is working fine. I deleted the variable and recreated again and mapped the derivation and it is fine now. May be I made a mistake last time...
Sorry about that...

Posted: Mon Feb 02, 2004 5:20 pm
by chulett
No problem... glad to hear it is working fine for you now!