Read Hash file from BASIC Code

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

Post Reply
ipc24
Participant
Posts: 2
Joined: Fri Jan 02, 2004 4:02 am

Read Hash file from BASIC Code

Post 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,
davidthree
Participant
Posts: 11
Joined: Fri Nov 07, 2003 11:14 am

Post 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
ipc24
Participant
Posts: 2
Joined: Fri Jan 02, 2004 4:02 am

Thanks

Post by ipc24 »

:D
Thank you very much!!!
Now all it is working fine.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Re: Thanks

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
bizz
Participant
Posts: 2
Joined: Mon Aug 25, 2003 6:50 am

Re: Read Hash file from BASIC Code

Post 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
tonystark622
Premium Member
Premium Member
Posts: 483
Joined: Thu Jun 12, 2003 4:47 pm
Location: St. Louis, Missouri USA

Post by tonystark622 »

Try trimming the key values, Alain.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

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.
Jdrost
Participant
Posts: 17
Joined: Wed Jun 28, 2006 3:32 am

How do I fill <PathAndNameToYourConfigHashFile>

Post 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
Kind regards,

Johannes Drost
Post Reply