Break operation in row wise comparison

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
sreesuku2
Participant
Posts: 45
Joined: Tue Oct 22, 2013 11:45 am

Break operation in row wise comparison

Post by sreesuku2 »

Hi Team,

I am trying to do a row wise comparison. Is there any way I can break the operation based on a condition ?

I have the below rows
Row | Dept | Hours
1 ABC 10
2 ABC 15
3 XYZ 10
4 ABC 15
5 ABC 20

I want to break the operation at row 3 where Dept Not equal to the following one. In this case ABC <> XYZ, then comparison should break. Event at row 4 also its XYZ <> ABC, but it should not go there. The comparison operation should break at the first instance itself.

My actual intent is to consider only those hours before the first dept change. Any other logic is also welcome

- Sree
prasson_ibm
Premium Member
Premium Member
Posts: 536
Joined: Thu Oct 11, 2007 1:48 am
Location: Bangalore

Post by prasson_ibm »

Hi Sree,

You can do this with the help of transformer using stage variables.

Store your current value to stage variable.

CURR=InputROW
COMPARISION=if (PREV<>CURR) THEN 1 ELSE 0)
PREV=CURR

In the constraint define CMPARISION=0
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Re: Break operation in row wise comparison

Post by chulett »

sreesuku2 wrote:The comparison operation should break at the first instance itself.
So... you only want the first two records and all records after the first 'break' should be skipped? If so you'll need different code... something like:

Code: Select all

svFirstDept =>  If IsNull(svFirstDept) then DEPT else svFirstDept
svIsBroken  =>  Not(svIsBroken) and DEPT <> svFirstDept
Then pass along rows which are "Not(svIsBroken)". Set the InitialValue of svFirstDept to @FALSE. Note that expressions automatically evaluate to true or false so (generally) there's no need to specifically use the System Variables or 0/1 and you can treat them as Boolean values - hence the suggestion to use "Not(x)" as the constraint rather than "If X then @FALSE else @TRUE".

The code should be pretty close if I understood the requirement. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The important piece of information here is that you use the stage variable in a Constraint expression, so that no rows are transferred to output once your break condition has been met.
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 »

If you enclose in Code tags, you will get a readable format.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sreesuku2
Participant
Posts: 45
Joined: Tue Oct 22, 2013 11:45 am

Post by sreesuku2 »

Thanks Ray. I just changed the format
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Make sure you define and initialize the variables properly. The first is a three character string set to @NULL and the second is an integer set to @FALSE in my case. This so svFirstDept shows 'ABC' all the way down.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Better to initialise to "???" rather than @NULL - comparisons to @NULL always return @NULL.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

True... except for the fact that the code I posted specifically checks for null. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

If this is working for you then good. My only thoughts I've already posted... I educate people working for me to not use those " = 1 " or " = 0 " comparisons, they get called out and corrected during the peer review. One example:

Code: Select all

If SVPreEmp = SVCurrEmp then 1 else 0
Should be simply:

Code: Select all

SVPreEmp = SVCurrEmp
As with any other derivation that doesn't do an assignment, it will automagically evaluate to either @TRUE (1) or @FALSE (0). And the name of the stage variable should make it perfectly obvious what it means when it is true versus when it is false.
-craig

"You can never have too many knives" -- Logan Nine Fingers
sreesuku2
Participant
Posts: 45
Joined: Tue Oct 22, 2013 11:45 am

Post by sreesuku2 »

Sure craig.

I will take that point. It a valid one. Thanks for your inputs

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

Post by chulett »

8)

It's all about readability and clarity of purpose.
-craig

"You can never have too many knives" -- Logan Nine Fingers
asorrell
Posts: 1707
Joined: Fri Apr 04, 2003 2:00 pm
Location: Colleyville, Texas

Post by asorrell »

chulett wrote:8)

It's all about readability and clarity of purpose.
As opposed to "job security"? :-)
Andy Sorrell
Certified DataStage Consultant
IBM Analytics Champion 2009 - 2020
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Exactly! Wait... what? :shock:
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Some developers seem to have the attitude that lack of documentation = job security.

Anyone working for me produces the design and documentation first, before being given the chance to play with DataStage (or whatever tool).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply