replacing null column with some value and assigning a keyval

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

DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
prasad111
Premium Member
Premium Member
Posts: 173
Joined: Fri May 19, 2006 10:53 am

Post 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
Last edited by prasad111 on Wed Nov 01, 2006 5:24 pm, edited 2 times in total.
prasad111
Premium Member
Premium Member
Posts: 173
Joined: Fri May 19, 2006 10:53 am

Post 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)
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
Last edited by ray.wurlod on Wed Nov 01, 2006 11:19 pm, edited 1 time in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
prasad111
Premium Member
Premium Member
Posts: 173
Joined: Fri May 19, 2006 10:53 am

Post 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........
Post Reply