from examples here and there I've created a routine to get data from a hashed file. This routine will be used in a workflow:
-fillhash
-startloop
-read data from hash into variables
-call some jobs for these variables
-end loop
As you will see in the code below, the routine now asks for the hashfile, the keyvalue and the column. But: the column is a numeric value.
I would like to change this to column-name.
Any idea how this can be done?
Code: Select all
*
* Executes a lookup against a hashfile, it will return the value from column in the other param
*
* Input Parameters : hashfile: hashfile in which to look (always in projectdir)
* keyvalue:value in the keycolumn of this hashfile
* column : columnnumber of which the value should be returned
* 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 = 'getvaluefromanyhash'
Common /HashLookup/ FileHandles(100), FilesOpened
Deffun DSRMessage(A1, A2, A3) Calling "*DataStage*DSR_MESSAGE"
HashTable = hashfile
HashKey = keyvalue
ColumnPosition = column
* Attempt to find the table name in our cache.
Locate HashTable in FilesOpened Setting POS Then
Read Rec From FileHandles(POS), HashKey Then
Ans = Rec<ColumnPosition>
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.
Open 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 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