How to open and do lookup in a hashfile from 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
kmk143
Participant
Posts: 7
Joined: Thu May 27, 2004 4:31 am

How to open and do lookup in a hashfile from a routine

Post by kmk143 »

Hi,
The requirement is that a string like "1.1.1" or "1.1.1.2" will be read from an input file. There are two hash files called level3 and level4. The string can be found either in level3 file or level4 file. This depends on whther string is 3rd level ("1.1.1") or 4th level ("1.1.1.2"). But same string cannot be available in both the hash files.
If the string is found in level3 file, some processing need to be done. If the string is found in level4 file, some other processing need to be done.
I thought if I can write a subroutine where in I can open both the hash files and do the lookup, then the job will be compact with only one transformer.
Is it possible to open and do lookup on hash file using basic code?
If so Can some body give me a code snippet to do it?

Thanks in advance.
Regards
kmk143
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

While you could write a routine to do this, there's no reason to do so. All you need is one transformer, so the job will still be 'compact'. :wink:

Simply use a single transformer, two hash file lookup stages and two reference links back to that single transformer. Use the same field in both key fields and then check them both in the derivation for the target field. Based on the success or failure of each lookup, you can do your processing.

Does that make sense? Perhaps your 'processing' could be encapsulated into a routine so this can all stay inside one transformer...
-craig

"You can never have too many knives" -- Logan Nine Fingers
kmk143
Participant
Posts: 7
Joined: Thu May 27, 2004 4:31 am

Post by kmk143 »

Thank you. Actually the "processing" it self is to do number of lookups on a single hash file. Hence I need to know how to open a hash file and do the lookups.
Pls. provide here some sample coding to do it.
Thanks in advance.
Regards
MuraliK
mleroux
Participant
Posts: 81
Joined: Wed Jul 14, 2004 3:18 am
Location: Johannesburg, South Africa
Contact:

Post by mleroux »

In that case, perhaps you may want to use more than one transformer. It will make your life easier and the life of whoever has to maintain the job in future.

Pass the first transformer's two outputs, from constraints:

Code: Select all

level3.NOTFOUND and level4.NOTFOUND
or

Code: Select all

Not(level3.NOTFOUND) and Not(level4.NOTFOUND)
(whichever you fancy) to two seperate transformers, where you can then do your other lookups.
Morney le Roux

There are only 10 kinds of people: Those who understand binary and those who don't.
kmk143
Participant
Posts: 7
Joined: Thu May 27, 2004 4:31 am

Post by kmk143 »

Thank you. May be I need to be more clear on the requirement.
I need to do lookups on the same hash file for 10 input values. In general I need to have 10 instances of the hash file stage in my job. Instead if I can write a routine where the input values can be passed as a string. Thus we access the hash file with in the routine and can lookup the inputs. Here I believe we need to open hash file one time. Hence I want to know how to open and do a lookup on hash file through basic code.
Thanks in advance
kmk143
Post Reply