User Tools

Site Tools


order_set_view_sort_order_expression_.htm
Navigation:  Language Reference > 5 - Declaration Attributes > Variable and Entity Attributes >====== ORDER (set view sort order expression) ====== Previous pageReturn to chapter overviewNext page

ORDER(expression list)

blk2blue.jpg

ORDER Specifies an expression list used to sort the records in the VIEW.
expression list A single string constant containing one or more expressions. Each expression in the list must be separated by a comma from the preceding expression.

The ORDER attribute (PROP:ORDER) specifies an expression list used to sort the records in the VIEW. The expressions within the expression list evaluate from left to right, with the leftmost expression defining the most significant sort and the rightmost defining the least significant sort. Expressions that begin with a unary minus (-) sort in descending order.

The expression may reference any field in the VIEW, at all levels of JOIN structures. The expressions in the expression list may contain any valid Clarion language expression. The expression list is evaluated at runtime (just like the EVALUATE procedure), therefore you must BIND all variables used in the expression.

For non-SQL file systems, the VIEW will use keys to do most of the sorting wherever possible, sorting only groups of records which have the same key values, keeping one 'bucket' sorted. Therefore, additional sort fields on top of a key can be quite efficient.

For SQL file systems, PROP:SQLOrder is an SQL-only equivalent to PROP:ORDER. For both of these properties, if the first character of the expression assigned to them is a plus sign (+) then that expression is concatenated to the existing order expression. For PROP:SQLOrder, if the first character of the expression assigned is a minus sign (-) then the existing order expression is concatenated to that expression. If the first character is not plus (or minus), the new expression overrides the existing expression.

Example:

!Orders sorted in descending date order, then customer name (by name within each date)

ViewOrder VIEW(Customer),ORDER('-Hea:OrderDate,Cus:Name')

          PROJECT(Cus:AcctNumber,Cus:Name,Cus:Zip)

          JOIN(Hea:AcctKey,Cus:AcctNumber)           !Join Header file

           PROJECT(Hea:OrderNumber,Hea:OrderDate)

           JOIN(Dtl:OrderKey,Hea:OrderNumber)        !Join Detail file

            PROJECT(Det:Item,Det:Quantity)

            JOIN(Pro:ItemKey,Dtl:Item)               !Join Product file

             PROJECT(Pro:Description,Pro:Price)

            END

           END

          END

         END

CODE

ViewOrder{PROP:ORDER} = '-Hea:OrderDate,Pro:Price-Det:DiscountPrice'

!Orders sorted by greatest discount within descending order date

!ABC Implementation example of PROP:SQLORDER

!For browse, after files and window are opened

BRW1::View:Browse{PROP:SQLOrder} = 'Phone'  

!where Phone is a column name in SQL database

!For reports, after files and progress window are opened:

Process:View{PROP:SQLOrder} = 'au_lname'

!where au_lname is a column name in SQL database

See Also:

BIND

UNBIND

EVALUATE

order_set_view_sort_order_expression_.htm.txt · Last modified: 2021/04/15 15:57 (external edit)