What's the best method to write complex derivations?

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

abyss
Premium Member
Premium Member
Posts: 172
Joined: Thu May 22, 2014 12:43 am

What's the best method to write complex derivations?

Post by abyss »

Hi,
I have a job that requires implementing complicated derivation logic in a couple of columns and a mapping table is not suitable for some reason. I am just wondering, what's the best method to write the code without too much error?

Is there any 3rd party derivation editor available? Something that can highlight the key words and variables?

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

Re: what's the best method to write complex derivations?

Post by chulett »

abyss wrote:mapping table is not suitable for some reason
Not really sure what that means. "Mapping table"? Are you talking about rules driven derivations? Regardless, for Server or Sequence jobs it is easy to build a "test harness" - a custom BASIC routine with the derivation logic in it that you can test with various input values to ensure what comes out the end is correct. Unless you're attempting to integrate a rules engine in there somewhere.

As to your last question - UltraEdit.
-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 answer to this one has to be "it depends".

If you could indicate what kind of "complex derivation" you have in mind, then we could perhaps be more specific.

If there's one best practice for avoiding errors in expression construction, it would be to use the Expression Editor and choose all operators and operands (except numeric constants) from menus.
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 »

I was assuming they meant "logic" errors more than actual syntax errors. Since they're, you know... complex. :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 »

Sometimes I answer the unasked question. Unknown unknowns, and all that...
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
FranklinE
Premium Member
Premium Member
Posts: 739
Joined: Tue Nov 25, 2008 2:19 pm
Location: Malvern, PA

Post by FranklinE »

ray.wurlod wrote:Sometimes I answer the unasked question. Unknown unknowns, and all that...
Ray, I really don't know what you're talking about. :lol:

I was a big fan of Kedit in its heyday. Since I don't get to make purchasing decisions, I had to take SlickEdit when Kedit died a quiet death. It is clunky, but does everything I ask of it.
Franklin Evans
"Shared pain is lessened, shared joy increased. Thus do we refute entropy." -- Spider Robinson

Using mainframe data FAQ: viewtopic.php?t=143596 Using CFF FAQ: viewtopic.php?t=157872
asorrell
Posts: 1707
Joined: Fri Apr 04, 2003 2:00 pm
Location: Colleyville, Texas

Post by asorrell »

UltraEdit Rules! Too bad it doesn't have the syntax checking for DataStage pre-built!
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 »

But it does, my friend - at least as a downloadable wordfile. Go here and scroll down to DataStage BASIC. I used to tweak it to my tastes which from what I recall is very easily done. Now what they don't have is one for Informatica. :(
-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 »

Nice! Had no idea someone had done that.
Andy Sorrell
Certified DataStage Consultant
IBM Analytics Champion 2009 - 2020
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

chulett wrote: Now what they don't have is one for Informatica. :(
You can have that created easily, just add keywords in C1, C2, C3 tags and you are done. Just need to make sure its sorted (or that may not be a requirement anymore).
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Of course, just haven't really bothered yet. It's on my Rainy Day List, page 12. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
IASAQ
Premium Member
Premium Member
Posts: 31
Joined: Wed May 04, 2016 11:07 am
Location: Montréal

Post by IASAQ »

Maybe I can surf on this thread as "complex derivation" had an exact match to what I was looking for.

My guess is that by complex derivation, the OP was thinking about when, for a single output field, you could have multiple lines of codes, including assigning variables to end up with a final value to be mapped to the output field.

Unless I'm mistaken, in a derivation expression, you can't assign work variables. From what I could gather from the short time I've been trying to work with Datastage, derivations seems more like this:

Code: Select all

if inputField = true then
    "TRUE"
else
    "FALSE"
than this:

Code: Select all

if inputField = true
    tmpStr = "this is maybe my lucky string"
    tmpInt = WordCount(tmpStr)

    if (tmpInt) = 7 then
        "You Win? Security!"
    else
        "Put more coins in the slot machine, sucker!"
else
    "Marvin! Kick him out of my casino!"
After reading another thread related to this subject, looks like you'd have to use multiple stage variables to accomplish the goal instead of having everything in a single derivation expression. Or use a custom routine written in C++ or BASIC.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

No, complex expressions are OK in DataStage BASIC, but you have to know the rule that every multi-statement block has to be terminated with an END statement.

However, in a derivation expression things are different. You're right that you cannot assign work variables (use stage variables for these). A derivation expression is one that must produce a result. It is an expression that could be used on the right hand side of an assignment statement in a routine.

That said, your example could be done in a single expression with no stage variables. It would just be ugly.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
IASAQ
Premium Member
Premium Member
Posts: 31
Joined: Wed May 04, 2016 11:07 am
Location: Montréal

Post by IASAQ »

ray.wurlod wrote:No, complex expressions are OK in DataStage BASIC
But routines written in BASIC are not available in parallel jobs, except with BASIC Transformer and we already discussed that I believe.
ray.wurlod also wrote:However, in a derivation expression things are different. You're right that you cannot assign work variables (use stage variables for these). A derivation expression is one that must produce a result. It is an expression that could be used on the right hand side of an assignment statement in a routine.

That said, your example could be done in a single expression with no stage variables. It would just be ugly.
So for the sake of comprehending correctly. a transformation that would require 5 manipulations for a single input field would require 5 stage variables if we wanted to be clean right?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Expressions in parallel transformer stages are actually in BASIC. They are translated to C++ during "compilation". However, multi-statement blocks are not available in expressions; indeed no form of statement is available in an expression.

I continue to maintain that your example could be done in a single expression with no stage variables. But using stage variables would make it easier to understand and therefore more easily maintained.
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