Read Hash file from BASIC Code
Moderators: chulett, rschirm, roy
Read Hash file from BASIC Code
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,
-
- Participant
- Posts: 11
- Joined: Fri Nov 07, 2003 11:14 am
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:
You can call the function in your batch job using
(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
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
Code: Select all
Call DSU.DirectoryHashLookup(<ReturnValue>, <PathAndNameToYourConfigHashFile>, <KeyValue1>, <KeyValue2>,1)
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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Re: Thanks
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.ipc24 wrote::D
Thank you very much!!!
Now all it is working fine.
I suspect you're working on a server canvas.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Re: Read Hash file from BASIC Code
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
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
-
- Premium Member
- Posts: 483
- Joined: Thu Jun 12, 2003 4:47 pm
- Location: St. Louis, Missouri USA
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Multi-column keys in hashed files have @TM as a separator character. Your key expression therefore must be of the form
Code: Select all
key1 : @TM : key2
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
How do I fill <PathAndNameToYourConfigHashFile>
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
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:
You can call the function in your batch job usingCode: 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
(assuming your hash file stores parameter values in the first field after the key(s)).Code: Select all
Call DSU.DirectoryHashLookup(<ReturnValue>, <PathAndNameToYourConfigHashFile>, <KeyValue1>, <KeyValue2>,1)
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
Kind regards,
Johannes Drost
Johannes Drost