Page 1 of 1
Extracting from a hash file in numeric order.
Posted: Mon Nov 24, 2003 9:20 pm
by Baldo
Hi,
I am writing a custom Server Routine to read out of a hash file. The only problem is that the key is a number. I have tried:
That returns data sorted alphabetically (1, 10, 2, 3, etc).
I have done searches on previous topics and found nothing like this (lots on sorting, but none for numeric keys). Ideally, I would like to avoid having to use a separate job with a sort stage to a sequential file (which is the only way I know) as this is a transform routine to be reused.
Thanks,
Chris.
Posted: Mon Nov 24, 2003 10:48 pm
by kcbland
Code: Select all
EXECUTE \SSELECT yourhashfile BY yourkeycolumn FMT "12R"\
Your primary key column must be showing as a left justified field in the hash file dictionary. Override this format using the FMT keyword when you execute the select. You cannot use a BASIC select, you must switch to an EXECUTE or PERFORM.
Posted: Mon Nov 24, 2003 10:52 pm
by kcbland
If you want to see a good online help manual, check out:
http://members.aol.com/_ht_a/mbtexts/31.html
In fact, there's a wealth of information here for anyone who wants to dive into Universe BASIC full time.
Posted: Mon Nov 24, 2003 11:21 pm
by Baldo
Hi Kenneth,
Thanks for your reply. It compiled alright, but when I tested it, I got the following error:
Code: Select all
Retrieve: syntax error. Unexpected sentence without filename. Token was "".
Scanned command was SSELECT 'LOG' BY '@ID' FMT '12R'
Also, can I select into a numbered select list in an EXECUTE?
Thanks,
Chris.
Posted: Mon Nov 24, 2003 11:28 pm
by kcbland
It would only help to have your exact command.
I'm guessing you've got single quotes all over the place and that's wrong.
Try:
Code: Select all
EXECUTE \SSELECT LOG BY @ID FMT "12R"\
Is it imperative that you select to a list? If so, just add the appropriate keywords.
Please visit here, as it has all of the answers:
http://hometown.aol.com/mbtpublish/1.html
Posted: Mon Nov 24, 2003 11:58 pm
by Baldo
Hi Kenneth,
I am looking at the web pages you posted the address of now. But so you know, I did actually have it exactly as you put it in (with no quotes - apart from those you specify). It just seems to parse it that way.
I will write back if I still can't do it.
Thanks,
Chris.
Posted: Tue Nov 25, 2003 12:41 am
by Baldo
Hi,
I am still having no luck. Any advice would be appreciated.
Thanks,
Chris.
Posted: Tue Nov 25, 2003 1:01 am
by Baldo
Got it!
I assumed that the 'yourhashfile' part of your code refered to a file variable. I have found that it refered to the actual name (a mistake on my part - but that was how it worked in the select without the execute). I had an OPEN statement above and assumed that this operated on the open hashfile referenced by the LOG file var.
Thanks for your help.
Regards,
Chris.
Posted: Tue Nov 25, 2003 5:42 am
by ray.wurlod
If you want the SSELECT filevariable statement to perform a numeric sort of the keys, change the definition of @ID in the file dictionary so that it is right-justified rather than left justified. For example:
Code: Select all
UPDATE DICT hashedfilename SET FORMAT = '10R' WHERE @ID = '@ID';