How to set the stage variable within a routine?

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
aravindk
Participant
Posts: 41
Joined: Tue Dec 09, 2003 8:59 am

How to set the stage variable within a routine?

Post 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.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
aravindk
Participant
Posts: 41
Joined: Tue Dec 09, 2003 8:59 am

Post 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.
raju_chvr
Premium Member
Premium Member
Posts: 165
Joined: Sat Sep 27, 2003 9:19 am
Location: USA

Post by raju_chvr »

Did u try using the same if...then..else in the column derivation within Transformer, instead of a Routine ?
aravindk
Participant
Posts: 41
Joined: Tue Dec 09, 2003 8:59 am

Post by aravindk »

Yes I did. While it doesnt return any error, it doesnt give the required output.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
raju_chvr
Premium Member
Premium Member
Posts: 165
Joined: Sat Sep 27, 2003 9:19 am
Location: USA

Post by raju_chvr »

there u go .. U have a very elegant solution !
aravindk
Participant
Posts: 41
Joined: Tue Dec 09, 2003 8:59 am

Post by aravindk »

Worked like Charm! elegant solution indeed....

Thanks to both of you!
aravindk
Participant
Posts: 41
Joined: Tue Dec 09, 2003 8:59 am

Post 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,
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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?
-craig

"You can never have too many knives" -- Logan Nine Fingers
aravindk
Participant
Posts: 41
Joined: Tue Dec 09, 2003 8:59 am

Post by aravindk »

In my case, both StageVar1 and StageVar2 are same, giving me the impression that it assigns StageVar2 *after* deriving StageVar1.
aravindk
Participant
Posts: 41
Joined: Tue Dec 09, 2003 8:59 am

Post 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...
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

No problem... glad to hear it is working fine for you now!
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply