Page 2 of 2

Posted: Wed Nov 01, 2006 9:02 am
by DSguru2B
Where exactly are you getting stuck?
As Craig suggested, go into the source code of UtilityHashLookup() change the specific code and make your own routine. Here ill help you with that.

Code: Select all

*************************************************************************
* Copyright (C) 2004, 1997-2003 Ascential Software Corporation. All Rights Reserved. *
* This code may be copied on condition that this copyright              *
* notice is included as is in any code derived from this source.        *
*************************************************************************
*
* Executes a lookup against a hashed file using a key
*
* Input Parameters :   Arg1 = Fully Qualified Path Of Hash Table
*                      Arg2 = Hash Key Value
*                      Arg3 = Column Position to return.
*                             If empty, return entire row in a dynamic array.
*
* Return  Values: If no record found, return value is:     "**RECORD NOT FOUND**".
*                 If hash file not found, return value is: "**TABLE NOT FOUND**"
*
*		  Note that the above strings may be localised.
*

    RoutineName = 'myUtilityHashLookup'

    Common /HashLookup/ FileHandles(100), FilesOpened

    Deffun DSRMessage(A1, A2, A3) Calling "*DataStage*DSR_MESSAGE"

    HashTable = Arg1
    HashKey = Arg2
    ColumnPosition = Arg3
    PositionReturn = 0

    * Determine if we are returning one column or entire row.
    If Num(ColumnPosition) then
    	ColumnPosition = Int(ColumnPosition)
        If ColumnPosition > 0 and ColumnPosition < 99999 Then
            PositionReturn = 1
        End
    End
 	
    * Attempt to find the table name in our cache.
    Locate HashTable in FilesOpened Setting POS Then
     	Read Rec From FileHandles(POS), HashKey Then
            If PositionReturn Then Ans = Rec<ColumnPosition> Else Ans = Rec
        End Else
            Ans = DSRMessage("DSTAGE_TRX_I_0010" , "**RECORD NOT FOUND**", "" )
        End
    End Else
	* Table is not in cache of opened tables, so open it.
        OpenPath HashTable To FileHandles(POS) Then
            FilesOpened<-1> = HashTable
            Read Rec From FileHandles(POS), HashKey Else
                Rec = DSRMessage("DSTAGE_TRX_I_0010" , "**RECORD NOT FOUND**", ""  )
            End
            If PositionReturn And Rec <> DSRMessage("DSTAGE_TRX_I_0010" , "**RECORD NOT FOUND**", ""  ) Then
                Ans = Rec<ColumnPosition>
            End Else
                Ans = Rec
            End
        End Else
            Rec = DSRMessage("DSTAGE_TRX_I_0011" , "**TABLE NOT FOUND**", "" )
            Ans = Rec
        End
    End
Now copy paste this code into a new user-defined routine and name it 'myUtilityHashLookup'. Specify three arguments as Arg1, Arg2 and Arg3. And for Arg1, send in the fully qualified path of the hashed file name. Try this part first, and test it after compiling it. See if it retrieves the correct results. Lets get this part working first.

Posted: Wed Nov 01, 2006 1:47 pm
by prasad111
DSguru2B wrote:Where exactly are you getting stuck?
As Craig suggested, go into the source code of UtilityHashLookup() change the specific code and make your own routine. Here ill help you with that. Now copy paste this code into a new user-defined routine and name it 'myUtilityHashLookup'. Specify three arguments as Arg1, Arg2 and Arg3. And for Arg1, send in the fully qualified path of the hashed file name. Try this part first, and test it after compiling it. See if it retrieves the correct results. Lets get this part working first.
I got it thanks a lot. The mistake was mentioning the column names in Arg3, we should mention the col-1

col1 | col2 | col3
1 |key_value| 0
2 |attribute |unknown

in arg 3 i have to mention 2
If(IsNull(DSLink4.FIRSTNAME)) Then myUtilityHashLookup('/proj/aspnd/dev/work/HFile/temp11_prasad_test',1,2) Else DSLink4.FIRSTNAME

if we use the above condition it is working....

once again thanks a lot..........I appreciate the patience and help

Regards
Prasad

Posted: Wed Nov 01, 2006 2:48 pm
by prasad111
DSguru2B wrote:Where exactly are you getting stuck?
As Craig suggested, go into the source code of UtilityHashLookup() change the specific code and make your own routine. Here ill help you with that.
Now copy paste this code into a new user-defined routine and name it 'myUtilityHashLookup'. Specify three arguments as Arg1, Arg2 and Arg3. And for Arg1, send in the fully qualified path of the hashed file name. Try this part first, and test it after compiling it. See if it retrieves the correct results. Lets get this part working first.
For curisoity and performance wise, how fast will it be, if I use this in an if else condition..........
If (Link1.VENDOR_CD = (myUtilityHashLookup('/proj/aspnd/dev/work/HFile/HCDMASTERVALUE',5,3)) or (myUtilityHashLookup('/proj/aspnd/dev/work/HFile/HCDMASTERVALUE',6,3) or (myUtilityHashLookup('/proj/aspnd/dev/work/HFile/HCDMASTERVALUE',7,3) or (myUtilityHashLookup('/proj/aspnd/dev/work/HFile/HCDMASTERVALUE',8,3)) Then myUtilityHashLookup('/proj/aspnd/dev/work/HFile/HCDMASTERVALUE',5,5) Else myUtilityHashLookup('/proj/aspnd/dev/work/HFile/HCDMASTERVALUE',4,5)

Posted: Wed Nov 01, 2006 3:01 pm
by ray.wurlod
Compared to what? Why don't you do the research and let us know? Without tying up resources, we could only supply a theoretical answer in any case.

Posted: Wed Nov 01, 2006 3:07 pm
by DSguru2B
I agree. You need to test it out. Performance is a very vague term. It really depends upon your data size, processing window.

Posted: Wed Nov 01, 2006 10:01 pm
by prasad111
ray.wurlod wrote:Compared to what? Why don't you do the research and let us know. Without tying up resources, we could only supply a theoretical answer in any case. ...
Other way of achieving was hardcoding it, I checked out for running this job for 50,000 records with hardcoding it took 12 min with hash file it took 14 min, its almost the same........