Posted 07 August 2002 - 11:35 PM
I have two issues,
1. In Reports there are only 5 sort values SV1…SV5. What do I do if I have more than five sort values.
2. In another report I would like to have the sort as an option on the start up screen.
The report is being sorted only by SV1 which is not a key of the primary file. Is the only way to do that is to create two different LRs one with the sort value and the other without? I sure hope I am wrong here otherwise I am in trouble because there are quite a few reports that need to be changed J
Your help is appreciated,
Posted 08 August 2002 - 04:52 AM
You can use scratch vars as sort variables.
In Sort Select Logic, you assign the sort var.
$$SORT = FIELD1 + FIELD2 + FIELD3
You should always DEFINE the scratch sort var, so that it is the correct length. This helps performance a bit.
Posted 08 August 2002 - 05:15 AM
If you use this method, you actually also need to ensure that the fields are in the right place...
FIELD1 Alpha 5
FIELD2 Alpha 10
FIELD3 Alpha 3
DEFINE $SORT(,18) is a good thing to do, then
$SORT(1,3) = FIELD1
$SORT(4,13) = FIELD2
$SORT(14,16) = FIELD3
Posted 08 August 2002 - 07:27 AM
Also remember that the SORT feature works by creating a temporary file keyed on the Sort Variables + the key to the Primary file (plus 1 character to indicate the Sort level if multiple sorts are in a single function), and the max keylength on PRO-Isam is 127 bytes. A numeric sort variable takes up 14 bytes btw.
That can be another reason for using DEFINE on Scratch Sort Variables.
There are loads of other SORT tips where that came from!
Posted 08 August 2002 - 09:42 AM
What Mr Rob has told is the easy way.
use temporary scratch variable for sorting and assign all the values to the scratch var.
$$SORT = FIELD1 + FIELD2 + FIELD3 + ...
do the assignment in sort Select Logic and just use this scratch var for sort.
Posted 08 August 2002 - 09:48 AM
Posted 08 August 2002 - 10:48 AM
$$SORT = FIELD1(1,3) + FIELD2(1,10) + FIELD3(1,3) ...
The important bit to note is you should build your $$SORT scratch var with the full lengths of the attributes you add to it, this ensures it includes any spaces at the end of strings.
If you just combine the attributes without specific lengths then any trailing spaces will be dropped and your sort will likely be incorrect.
Of course, if your attributes don't have trailing spaces (e.g. all 'LFZ' data) then it's not strictly neccessary, but it's a good habit to get into!
Don't learn from your own mistakes - it's safer and more entertaining to learn from the mistakes of others!
Just because you can, it doesn't mean you should!
Posted 08 August 2002 - 12:28 PM
$sort = pad(FIELD1) + pad(FIELD2) + pad(FIELD3)...
This requires that FIELD1 etc.. are defined with the correct maximum length.
The advantage is that you don't end up with hard-coded lengths all over your application so it's much easier to change things later!
Coding the global logic pad() is left as an exercise for the reader
Reply to this topic
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users