HF and Seq. file dynamic join

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
marc_brown98
Premium Member
Premium Member
Posts: 67
Joined: Wed Apr 14, 2004 11:33 am

HF and Seq. file dynamic join

Post by marc_brown98 »

I have a situation where I have a Hash file that I need to use as a lookup for descriptions to insert into a larger sequential file. The problem I am having is that the join to the sequential file depends on a value in the hash file, for example:

key Level Code Desc
______ ____ ________ ________________
52 BAL 2 11010100 PETTY CASH
52 BAL 1 12345600 REVENUE

Seq. File:
key Account_level1 Account_level2
______ _____________ ____________
52 BAL 8080 11010100
52 BAL 12345600 2500

If Level = 1 then I use account_level1 field, if level = 2, use account_level2, etc.

I would like to be able to do this in one pass, but the way I am looking at it would appear that I would have to make a pass through the data for each account_level. Any thoughts on an efficient way to accomplish this?

Thanks
Marc
roy
Participant
Posts: 2598
Joined: Wed Jul 30, 2003 2:05 am
Location: Israel

Post by roy »

Hi,
you can have multiple lookups for the hash file, each using a different column from your seq file.
in the transformer put the coresponding lookup value depending on the logic you have.
i.e.

Code: Select all

If link.Level = 1 Then lookup1.value Else lookup2.value
you can also use stage variables to make it mor simple:

Code: Select all

SV1 = If link.Level = 1 Then Lookup1.Value Else ""
SV2 = If link.Level = 2 Then Lookup2.Value Else ""
...

SVFinalVal = SV1 : SV2 : ...

Derivation column = SVFinalVal
in the stage variable examples the Else is an empty string.

IHTH,
Roy R.
Time is money but when you don't have money time is all you can afford.

Search before posting:)

Join the DataStagers team effort at:
http://www.worldcommunitygrid.org
Image
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Make the hashed file with three key columns (Key, Level, Code).

Perform two (separate) lookups.

The first uses
  • inlink.Key
    1
    inlink.Account_Level1
as the three reference key expressions.

The second uses
  • inlink.Key
    2
    inlink.Account_Level2
as the three reference key expressions.

One of them should succeed; you can detect which one in the Transformer stage, and output the appropriate description accordingly, for example

Code: Select all

If IsNull(lookup1.Key) Then lookup2.Desc Else lookup1.Desc
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
marc_brown98
Premium Member
Premium Member
Posts: 67
Joined: Wed Apr 14, 2004 11:33 am

Post by marc_brown98 »

ray and roy,
Thanks for the help. That was how I was kind of thinking it through, just wanted to verify.

Marc
marc_brown98
Premium Member
Premium Member
Posts: 67
Joined: Wed Apr 14, 2004 11:33 am

Post by marc_brown98 »

ray.wurlod wrote:Make the hashed file with three key columns (Key, Level, Code).

Perform two (separate) lookups.

The first uses
  • inlink.Key
    1
    inlink.Account_Level1
as the three reference key expressions.

The second uses
  • inlink.Key
    2
    inlink.Account_Level2
as the three reference key expressions.

One of them should succeed; you can detect which one in the Transformer stage, and output the appropriate description accordingly, for example

Code: Select all

If IsNull(lookup1.Key) Then lookup2.Desc Else lookup1.Desc
Ray,
Would the two lookups be in the same transform?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

marc_brown98 wrote:Would the two lookups be in the same transform?
Yes, it would. Doesn't absolutely need to be, but it is the simplest way to do it.
-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 »

Yes.

The derivation expression referring to lookup1 and lookup2 as link names should have been a clue! 8)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
roy
Participant
Posts: 2598
Joined: Wed Jul 30, 2003 2:05 am
Location: Israel

Post by roy »

Hi,
I just wanted to note that sometimes you could end up getting values from both links there for it would be best to use the lookup value coresponding your logic and not the lookup value, as I noted in my post.
IHTH,
Roy R.
Time is money but when you don't have money time is all you can afford.

Search before posting:)

Join the DataStagers team effort at:
http://www.worldcommunitygrid.org
Image
marc_brown98
Premium Member
Premium Member
Posts: 67
Joined: Wed Apr 14, 2004 11:33 am

Post by marc_brown98 »

Guys,
Thanks for all of the replies, I should have seen how to do it right away, but with a 2 week old baby girl, things are a little foggy now...:)
Post Reply