Weird behavior of routine when reading hashfile

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
kausmone
Participant
Posts: 39
Joined: Fri Sep 21, 2007 1:47 am
Location: Prague

Weird behavior of routine when reading hashfile

Post by kausmone »

Hello,

I have a server routine that reads all values of the key-field of a hash-file into an array using the code as below:

(note that STAGING_FOLDER and ARRAY_ELEMENT are arguments passed to the routine)

Code: Select all

DIM SubFileRunListArray(300)
MAT SubFileRunListArray=0

Openpath STAGING_FOLDER:"/SubFileRun_Types_HF" To FileVar
   Then SELECT FileVar to 1

ctrJobsToRun=0
   Loop 
        READNEXT key From 1 
           Else Exit
        ctrJobsToRun=ctrJobsToRun+1
        SubFileRunListArray(ctrJobsToRun) = key
   Repeat
    
Close FileVar 

Ans=SubFileRunListArray(ARRAY_ELEMENT)

When I test the routine to display the array elements, they are not in the sequence in which they are present in the hash-file, i.e. for example the 24th element in the hash_file appears as the 1st element of the array etc

Also, the data in the array element is not in the same case as that in the hash-file e.g. the key value in the file is ITM_STATUS_unknown but when I display the array element, it is seen as ITM_STATUS_UNKNOWN, i.e. all in uppercase. Is there some way to prevent these two phenomena?

Thanks,
Kaus
[/code]
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

It is a fundamental tenet of databases (and hashed files are implementations of database tables) that internal storage order is not under control of the user. Therefore you can not claim "the sequence which they are present in the hash-file (sic)".

The Select statement returns keys in whatever order the hashed file delivers them. If you want them sorted in key order, prefer the SSelect statement. If you want them sorted by some other column, then a different approach is required. You would need to generate the Select List externally (via a call to DSExecute perhaps) using a query.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kausmone
Participant
Posts: 39
Joined: Fri Sep 21, 2007 1:47 am
Location: Prague

Post by kausmone »

Hi Ray,

Thanks for your your reply; unfortunately it was cut off since I am not a premium member, but from what I could see, it is not possible to control in what sequence the data is stored inside the hash-file.

The hash-file being talked about below is created from a database table using an order-by clause in the SQL. When I view the data in the hash-file stage, it is seen in the right order, and also with the case intact with nothing converted to full uppercase. Is there no way then to ensure that the data is indeed in the required order? It is quite important to have the data in a particular order, hence the query.

Also, any ideas about the case-change?

Thanks,
Kaus
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Data are not stored in the ORDER BY order in the database table, nor are they stored in that order in the hashed file, and for exactly the same reason. You can not control the order of storage in a hashed file; you must use either a sequential file or a B-tree structure to preserve order (there are some other structures in parallel jobs, but that's not relevant here).

All data are case sensitive everywhere. What makes you think the case would be converted simply by loading into a hashed file?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

For less than 30c per day you can have premium membership and access to all the benefits thereof, including being able to read the entire posts of the five premium posters. Premium membership is one of the ways that DSXchange funds the hosting and bandwidth charges incurred by the site; in short, one way that keeps the site alive.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply