Sort
Started by
Guest_Sam_*
, Aug 07 2002 11:35 PM
12 replies to this topic
#1 Guest_Sam_*
Posted 07 August 2002 - 11:35 PM
Hi all,
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,
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,
#2
Posted 08 August 2002 - 04:52 AM
Hi,
You can use scratch vars as sort variables.
In Sort Select Logic, you assign the sort var.
ie
$$SORT = FIELD1 + FIELD2 + FIELD3
You should always DEFINE the scratch sort var, so that it is the correct length. This helps performance a bit.
Rob D.
You can use scratch vars as sort variables.
In Sort Select Logic, you assign the sort var.
ie
$$SORT = FIELD1 + FIELD2 + FIELD3
You should always DEFINE the scratch sort var, so that it is the correct length. This helps performance a bit.
Rob D.
#3
Posted 08 August 2002 - 05:12 AM
Sorry, forgot to mention....
If you dont want it to sort on anything, just dont set the $$SORT to anything.
Rob D.
If you dont want it to sort on anything, just dont set the $$SORT to anything.
Rob D.
#4
Posted 08 August 2002 - 05:15 AM
Just to be a pedant....
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
Pete
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
Pete
#6
Posted 08 August 2002 - 07:27 AM
You beat me to that one Peter!
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!
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!
#7
Posted 08 August 2002 - 07:35 AM
Thanks,
Forgot about that
Rob
Forgot about that
Rob
#9 Guest_Rajesh V.C_*
Posted 08 August 2002 - 09:42 AM
Hi
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.
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.
#10
Posted 08 August 2002 - 09:46 AM
Make sure you do it like Peter says....
DEFINE $SORT(,16)
$SORT(1,3) = FIELD1
$SORT(4,13) = FIELD2
$SORT(14,16) = FIELD3
Or it wont work
Rob
DEFINE $SORT(,16)
$SORT(1,3) = FIELD1
$SORT(4,13) = FIELD2
$SORT(14,16) = FIELD3
Or it wont work
Rob
#11 Guest_Rajesh V.C_*
Posted 08 August 2002 - 09:48 AM
For second prob you can create a temp cross reference file with SV1 as a key field. And before calling the report use an update to add records to this temp file and use this file in your report. This is the only solution or another way as you have mentioned. You can try this...
#12
Posted 08 August 2002 - 10:48 AM
Or of course you could skin the cat this way:
$$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!
$$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!
Nothing is foolproof to a sufficiently talented fool...
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!
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!
#13
Posted 08 August 2002 - 12:28 PM
Or even..
$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
$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
Nothing's as simple as you think
Reply to this topic
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users