Link to home
Start Free TrialLog in
Avatar of raj28
raj28

asked on

QSORT apI


Hello friends,
I have asked a question related to soring subfile which i got answer from daveslater .
But i couldn't understood how to use QSORT.
I have a subfile with values in status field like -
e.g  Open,Delete,Close in status field.
When the user types 1 - the subfile should be displayed records by - Open,Delete,Close.
Similarly  When the user types 2 - the subfile should be displayed records by - Delete,Close,Open.
i.e sorting status field on status field .
How can i use QSORT api in this situation ??
Do i need to pass the D,C,O paramter to this API procedure ??

Pls give an example.
Thanks and waiting..

Raj

Avatar of daveslater
daveslater
Flag of United States of America image

What you are trying to achieve is grouping, to perform this you will need some hidden fields in the subfile and some logic to populate these fields

say the fields are called
SORT01
SORT02

The logic would be ((** notes commedns addes for clarity and will not cust and past)

IF Status = 'Open'
eval sort01 = '1'   ** sort by Open first
eval sort02 = '3' ** sort by open last

elseif ststus = "delete"
eval sort01 = '2' ** sort bu delete second
eval sort02 = '1' ** sort by delete first

elseif ststus = "close"
eval sort01 = '3'  ** sort by close third
eval sort02 = '2' ** sort by close 2nd

endif


write subfile


You can then sort by the hidden field to perform the grouping.

The more criteria you have the more hidden fields you have and the more comples the IF statements

I hope that is clear

dave


Avatar of raj28
raj28

ASKER

Hi dave,
I understand a little bit but not more . Do i need to use QSORT api ?? How ??
Pls give example in detail ..as what u have given last time .

Thanks n waiting
Raj
Hi raj28
can you give a bit more info on what you are trying to achieve; they may be a better way of doing it.
I have just started a new job; this involves a lot more meetings so for a few weeks I will have less time to help here (untill I can get my Broadband connection to the 400)

Dave
Avatar of raj28

ASKER

Hi dave,
I couldn't understand how to use the hidden fields for sorting . Do u mean while loading the subfile - i have to move values to the hidden field (i.e if it is open then '1' , Close then '2' like this ) ?? If it is then how can i sort ?? Do i need to use QSORT api along with this ?? If yes then what are the parameters required for the procedure ??

I think u got my question . Thanks for your valuable time .

Raj..
Hi
It will be  Friday till I get a bit of time but if not one else posts domthing I will post the code then.

Dave
raj28:

Just in case this part is unclear, you _can't_ use the hidden fields to sort by.

That is, you can't sort the subfile at all.

That is, you have to write the subfile records in the order you want them sorted in. Sort before writing to the subfile.

The use of a hidden field would be so that you can read the subfile records back into the program and pass them to a sort function before writing them back out in a different order. If you don't store a hidden field with the subfile record, you'll have to supply the sort key for every record every time you re-send the records through the sort.

In short, the subfile is never sorted.

Instead, you sort an array or a multi-occurrence data structure or a temporary physical file or some other data object; then you write the data to the subfile again.

For qsort, you would have the subfile records possibly stored in an array and pass the address of the array to qsort. (It could be a MODS or a *usrspc or just a block of memory.) Then you'd write the subfile from the array, one subfile record at a time.

If the user chose a different sort, you'd pass the array address to qsort again and write the subfile records again from the array after the sort finished again. The "hidden" fields would be written to the subfile only if you wanted to read them back in. They could only be part of the array and never written to the subfile if that's how you wanted to do it.

(I got a little concerned that sorting subfiles _might_ be misunderstood.)

Now, since sometimes you want the sort order to be D-C-O and other times you want it to be O-D-C, qsort can be a useful choice for sorting. You will create a routine that can tell qsort whether to sort [O] as the highest value or the lowest value.

In fact, qsort doesn't really "sort" at all. It takes two elements from your array and then calls your routine and your routine tells qsort which of the two elements is higher. Qsort then rearranges them in memory if necessary, and then picks two more elements for your routine to compare. This means that qsort simply arranges the elements in whatever order _YOUR_ routine chooses for every pair of elements.

Qsort is written in such a way that it chooses the best elements to compare so that the whole opertaion goes fast if your routine is fast. It does this while also allowing total flexibility in sort sequencing. And that makes it suitable for D-C-O/O-D-C sorting even though there's no obvious pattern; the pattern will exist in the routine logic that you have to write.

Tom
Avatar of raj28

ASKER

Hi tiotta,
can u pls send me the code ??

thanks,
Raj
ASKER CERTIFIED SOLUTION
Avatar of daveslater
daveslater
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial