Jump to content


- - - - -

Sort


12 replies to this topic

#1 Guest_Sam_*

Guest_Sam_*
  • Guests

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,

#2 Rob Donovan

Rob Donovan

    rob@proivrc.com

  • Admin
  • 1,640 posts
  • Gender:Male
  • Location:Spain

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.

#3 Rob Donovan

Rob Donovan

    rob@proivrc.com

  • Admin
  • 1,640 posts
  • Gender:Male
  • Location:Spain

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.

#4 Peter Davies

Peter Davies

    Advanced

  • Members
  • PipPipPip
  • 96 posts
  • Gender:Male
  • Location:Bangkok, Thailand

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

#5 Guest_Sam_*

Guest_Sam_*
  • Guests

Posted 08 August 2002 - 05:44 AM

Thank you so much for the insight guys.

#6 Chris Pepper

Chris Pepper

    ProIV Guru

  • Members
  • PipPipPipPipPip
  • 369 posts
  • Gender:Male
  • Location:United Kingdom

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!

#7 Rob Donovan

Rob Donovan

    rob@proivrc.com

  • Admin
  • 1,640 posts
  • Gender:Male
  • Location:Spain

Posted 08 August 2002 - 07:35 AM

Thanks,

Forgot about that :)

Rob

#8 Guest_Dan Shannon's Evil Twin_*

Guest_Dan Shannon's Evil Twin_*
  • Guests

Posted 08 August 2002 - 07:43 AM

Use SQL :)

#9 Guest_Rajesh V.C_*

Guest_Rajesh V.C_*
  • Guests

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.

#10 Rob Donovan

Rob Donovan

    rob@proivrc.com

  • Admin
  • 1,640 posts
  • Gender:Male
  • Location:Spain

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

#11 Guest_Rajesh V.C_*

Guest_Rajesh V.C_*
  • Guests

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 Andy Jones

Andy Jones

    Member

  • Members
  • PipPip
  • 41 posts
  • Gender:Male

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!
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!

#13 Richard Bassett

Richard Bassett

    ProIV Guru

  • Members
  • PipPipPipPipPip
  • 696 posts
  • Location:Rural France

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 :)
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