Sortby-phrase

will

New Member
Hi I have an application with loads on browsers and would like a simple solution for sorting the browse using the START-SEARCH trigger (When the user clicks on the column label) and the Sortby-Phrase preprocessor.

In the start-search trigger I want to put something to this extent:

DEFINE VARIABLE lh AS HANDLE NO-UNDO.

ASSIGN lh = {&BROWSE-NAME}:CURRENT-COLUMN.

&scoped-define SORTBY-PHRASE BY lh:NAME

{&OPEN-QUERY-{&BROWSE-NAME}}

Where lh:NAME would be the column the user clicked on.

This Works

&scoped-define SORTBY-PHRASE BY DESCRIPTION
{&OPEN-QUERY-{&BROWSE-NAME}}

Is there anyway to substitute the 'Description' value follwing 'BY' by a variable name so that one procedure would work regardless of what the actual field is called to sort by.
If I am on the wrong path, it will be greatly appreciated if someone can shove me towards the right one .
Any hints, ideas , words of encouragement would be greatly appreciated.
 

tudorconstantin

New Member
Hi,
Your approach can't do the job, because the
&scoped-define SORTBY-PHRASE BY lh:NAME is evaluated at compile time and not at run time. You have to use the query asociated with the browse. Here is my suggestion:

DEFINE VARIABLE ColumnName AS CHARACTER NO-UNDO.
DEFINE VARIABLE hColumn AS HANDLE NO-UNDO.

hColumn = hBrowse:CURRENT-COLUMN. /*hBrowse is the handle to your browse*/
ColumnName = hColumn:NAME.

ASSIGN
ordonat = ((prevsel = ColumnName AND ordonat = FALSE ) OR prevsel<>ColumnName)
prevSel = ColumnName.
hQuery:QUERY-PREPARE(cQuery + " by " + columnName + STRING(IF ordonat THEN "" ELSE " desc ")).
hQuery:QUERY-OPEN ().
hQuery:REPOSITION-TO-ROW(1).


hQuery is a handle to the browse's query.
ordonat is a logical variable which if its true, then the column is currently ordered ascending and if false, the column is ordered descending or is not ordered at all.
prevsel is the name of the previous selected column.

I hope this helps.
 
Top