Logic in stage variable

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
saikiran
Premium Member
Premium Member
Posts: 18
Joined: Wed Aug 20, 2008 11:28 pm

Logic in stage variable

Post by saikiran »

Hello there,

Dataset o/p

RIDER RIDER_TYPE
x13 DR
x13 DR
x13 DR
x13 NULL
x13 DR
x13 DR
x13 DR
x13 DR
x13 DR
x13 MH
x13 MH
x13 MH
M10 VS
M10 VS
M10 VS
M10 BI
M10 NULL
M10 BI
M10 BI
M10 BI
M10 VS
M10 VS
M10 VS
M10 VS
M10 VS
M10 VS
M10 VS

OUTPUT
X13 DR:DR:DR:DR:DR:DR:DR:DR:MH:MH
M10 VS:VS:VS:BI:BI:BI:BI:VS:VS:VS

I have to concatinate first 10 values for each rider.If NULL is enountered in rider_type then I have to drop them.
Source is dataset( which is o/p of a join of couple of tables).

I am using stage variable to perform this logic.
To give you a overview of the things

one stage variable to perform concatination of field (rider_type).
Stage varaible for counting the incomming rows.

I am close but yet far from the solution.

Please let me know how to perform this and is there any other way to do the same.
I tried to do a search got some hints but I wast able to built on those.

Thanks
Sai
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Write the key and stage variable followed by a remove duplicates to retain last.
saikiran
Premium Member
Premium Member
Posts: 18
Joined: Wed Aug 20, 2008 11:28 pm

Post by saikiran »

Sainath,

Thanks for the response

Let me reiterate my qestion

I have to concatinate rider types for every unique rider option.
And only 10 such values have to be concatinated and if null is encountered in between it has to be droped.

Like this

X13 DRDRDRDRDRDRDRDRMHMH
M10 VSVSVSBIBIBIBIVSVSVS

Please let me know all the steps dealing with stage variables.

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

Post by ray.wurlod »

Stage variable has to be overwritten when the change key (generated in upstream Sort stage) is set, or accumulated otherwise.

Let's call the stage variable svOutputRow

Code: Select all

If inlink.changeKey = 1 Then inlink.col2value Else If IsNull(inlink.col2value) Then svOutputRow Else If Len(svOutputRow) >= 20 Then svOutputRow Else svOutputRow : inlink.col2value
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
saikiran
Premium Member
Premium Member
Posts: 18
Joined: Wed Aug 20, 2008 11:28 pm

Post by saikiran »

Ray,

Thanks for your responce

I implemeted the Change key using svValueHasChanged stage variable as below.Please correct me if I am wrong.

svPreviousValue = svCurrentValue
svCurrentValue = input.field
svValueHasChanged = If svCurrentValue = svPreviousValue Then 0 Else 1

svCounter = If svValueHasChanged Then svCounter + 1 Else svCounter
( I am not sure will I have to implement this)

Also I guess

If inlink.changeKey = 1 Then inlink.col2value Else If IsNull(inlink.col2value) Then svOutputRow Else If Len(svOutputRow) >= 20 Then svOutputRow Else svOutputRow : inlink.col2value
should be assinged to svOutputRow

If all this is correct the o/p of the above stage variable(svOutputRow) doest give me the conncatinated values as we expected. If gives me 2 byte values.

Please let me know
Thanks
Sai
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

First issue - your svPreviousValue stage variable must be the last one listed, or at the very least after any references to it.
-craig

"You can never have too many knives" -- Logan Nine Fingers
saikiran
Premium Member
Premium Member
Posts: 18
Joined: Wed Aug 20, 2008 11:28 pm

Post by saikiran »

Chulett,

I implemented in the followin oder ,I just mistyped it
(
svCurrentValue = input.field
svPreviousValue = svCurrentValue
)

Still I am not geeting the o/p which I need.

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

Post by chulett »

Show us all of the stage variables in the proper order, please.
-craig

"You can never have too many knives" -- Logan Nine Fingers
saikiran
Premium Member
Premium Member
Posts: 18
Joined: Wed Aug 20, 2008 11:28 pm

Post by saikiran »

Chulett,

This is order

svCurrentValue = input.field
svPreviousValue = svCurrentValue
svValueHasChanged = If svCurrentValue = svPreviousValue Then 0 Else 1

If svValueHasChanged = 1 Then inlink.col2value Else If IsNull(inlink.col2value) Then svOutputRow Else If Len(svOutputRow) >= 20 Then svOutputRow Else svOutputRow : inlink.col2value

Please let me know is this is the right way

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

Post by ray.wurlod »

The order is not correct. Also, stage variables in parallel jobs can not be null.

Code: Select all

svCol2NotNull  <==  NullToValue(inlink.col2value,"<<NULL>>")

svIsChanged  <==  svCol2NotNull <> svPreviousValue

svPreviousValue  <==  NullToValue(inlink.col2value,"<<NULL>>")

svOutputCol <== If svIsChanged Then If IsNull(inlink.col2value) Then "" Else inlink.col2value Else If IsNull(inlink.col2value) Then svOutputCol Else svOutputCol : inlink.col2value
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
saikiran
Premium Member
Premium Member
Posts: 18
Joined: Wed Aug 20, 2008 11:28 pm

Post by saikiran »

Ray:

Below is the O/P

DR
DR DR
DR DR DR
DR DR DR DR
DR DR DR DR DR
DR DR DR DR DR DR
DR DR DR DR DR DR DR
DR DR DR DR DR DR DR DR
DR DR DR DR DR DR DR DR MH
DR DR DR DR DR DR DR DR MH MH

REQUIRED O/P
DR DR DR DR DR DR DR DR MH MH

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

Post by ray.wurlod »

That's what the Remove Duplicates stage, mentioned by Sainath early in this thread, is for.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
saikiran
Premium Member
Premium Member
Posts: 18
Joined: Wed Aug 20, 2008 11:28 pm

Post by saikiran »

This worked perfectly fine.
Thanks a million for all the help

Sai
Post Reply