Page 1 of 1
Read Hash file from BASIC Code
Posted: Wed Feb 04, 2004 6:04 am
by ipc24
Dear all,
I have tried to read a Hash file from BASIC Code , using the routine "UtilityHashLookup", but it is not working if I have created the hash file, in the one directory path different than the Project Directory Path.
Could someone send me, some Basic Code, in order to read the hash file from the basic Code. It is very important for me, becouse I need to load the JOBS parameters, with the information included in the hash file.
Thanks all,
Posted: Wed Feb 04, 2004 6:48 am
by davidthree
Hi ipc
I use a modified version of UtilityHashLookup, which I call DirectoryHashLookup. It takes two keys (but can easily be modified). The code is as follows:
Code: Select all
*************************************************************************
* Author: David Thompson
* Date: 16th December 2003
* This function adapted from Ascential's UtilityHashLookup (see notice below)
*************************************************************************
*************************************************************************
* Copyright (c) 1997-2001 Ascential Software Inc. - 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, composited from two arguments
*
* Input Parameters : Arg1 = Hash Table Path & Name
* Arg2 = Hash Key Value 1
* Arg3 = Hash Key Value 2
* Arg4 = Column Position to return
* If empty, return entire row in a dynamic array.
*
* Return Values: If no record found, return value is: @NULL
* If hash file not found, return value is: "**TABLE NOT FOUND**"
*
*
**************************************************************************
RoutineName = 'DirectoryHashLookup'
Common /HashLookup/ FileHandles(100), FilesOpened
If IsNull(Arg2) Then Key1 = 'null' Else Key1 = Arg2
If IsNull(Arg3) Then Key2 = 'null' Else Key2 = Arg3
HashTable = Arg1
HashKey = Key1:@TM:Key2
ColumnPosition = Arg4
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 = @NULL
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 = @NULL
End
If PositionReturn And not(IsNull(Rec)) Then
Ans = Rec<ColumnPosition>
End Else
Ans = Rec
End
End Else
Rec = "**TABLE NOT FOUND**"
Ans = Rec
End
End
You can call the function in your batch job using
Code: Select all
Call DSU.DirectoryHashLookup(<ReturnValue>, <PathAndNameToYourConfigHashFile>, <KeyValue1>, <KeyValue2>,1)
(assuming your hash file stores parameter values in the first field after the key(s)).
I use the first key value to load an invocation ID, and the second to load some parameter for each invocation.
Hope that helps
cheers
Dave
Thanks
Posted: Wed Feb 04, 2004 8:24 am
by ipc24
:D
Thank you very much!!!
Now all it is working fine.
Re: Thanks
Posted: Wed Feb 04, 2004 3:25 pm
by ray.wurlod
ipc24 wrote::D
Thank you very much!!!
Now all it is working fine.
Your original post suggested that you were working on a 390 canvas. Clearly this is not the case; mainframe jobs generate COBOL code that is compiled and executed on a mainframe (OS/390) machine, and has no facility whatsoever for executing BASIC code.
I suspect you're working on a server canvas.
Re: Read Hash file from BASIC Code
Posted: Fri Oct 01, 2004 11:35 am
by bizz
Dear all,
I have tried to read a Hash file from BASIC Code , using the routine "UtilityHashLookup", but it's still not working. I'm able to LOCATE the hash and open it, but I can't find the record with my HashKey (Arg1,Arg2). Do you know if there is a problem with datatype for arg1,arg2? I've tried with a varchar, and another test with decimal and it's still not finding my record.
(I know that I have these record in my hashFile).
Thank's
Alain
Posted: Fri Oct 01, 2004 11:38 am
by tonystark622
Try trimming the key values, Alain.
Posted: Mon Aug 21, 2006 9:55 pm
by ray.wurlod
Multi-column keys in hashed files have @TM as a separator character. Your key expression therefore must be of the form
How do I fill <PathAndNameToYourConfigHashFile>
Posted: Tue Sep 05, 2006 7:49 am
by Jdrost
I have read your coding and I am trying to use it, but when I test the routine it fails to open the hashfile. I think I did not state the name and path of the hashfile correctly, but I do not know what I am doing wrong. I know that the pathname of the hashfile that I need is "c:\hash" and the name of the hashfile is "TestHash". I passed the parameter as "c:\hash\TestHash" with the result I mentioned above.
When I look with windows explorer in that path I find a folder with the same name as the hashfile containing 3 .30-files. I do not know if that is the hashfile, but the hashfile seems to be in that place.
Can you tell me how I state the name and path of the hashfile correctly in your routine?
Thanks in advance.
Johannes Drost
davidthree wrote:Hi ipc
I use a modified version of UtilityHashLookup, which I call DirectoryHashLookup. It takes two keys (but can easily be modified). The code is as follows:
Code: Select all
*************************************************************************
* Author: David Thompson
* Date: 16th December 2003
* This function adapted from Ascential's UtilityHashLookup (see notice below)
*************************************************************************
*************************************************************************
* Copyright (c) 1997-2001 Ascential Software Inc. - 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, composited from two arguments
*
* Input Parameters : Arg1 = Hash Table Path & Name
* Arg2 = Hash Key Value 1
* Arg3 = Hash Key Value 2
* Arg4 = Column Position to return
* If empty, return entire row in a dynamic array.
*
* Return Values: If no record found, return value is: @NULL
* If hash file not found, return value is: "**TABLE NOT FOUND**"
*
*
**************************************************************************
RoutineName = 'DirectoryHashLookup'
Common /HashLookup/ FileHandles(100), FilesOpened
If IsNull(Arg2) Then Key1 = 'null' Else Key1 = Arg2
If IsNull(Arg3) Then Key2 = 'null' Else Key2 = Arg3
HashTable = Arg1
HashKey = Key1:@TM:Key2
ColumnPosition = Arg4
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 = @NULL
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 = @NULL
End
If PositionReturn And not(IsNull(Rec)) Then
Ans = Rec<ColumnPosition>
End Else
Ans = Rec
End
End Else
Rec = "**TABLE NOT FOUND**"
Ans = Rec
End
End
You can call the function in your batch job using
Code: Select all
Call DSU.DirectoryHashLookup(<ReturnValue>, <PathAndNameToYourConfigHashFile>, <KeyValue1>, <KeyValue2>,1)
(assuming your hash file stores parameter values in the first field after the key(s)).
I use the first key value to load an invocation ID, and the second to load some parameter for each invocation.
Hope that helps
cheers
Dave