Restricting Sort Field Values by Highest/Lowest Rank

How to:

When you sort report rows using the BY phrase, you can restrict the sort field values to a group of high or low values. You choose the number of fields to include in the report. For example, you can choose to display only the 10 highest (or lowest) sort field values in your report by using BY HIGHEST (or LOWEST).

You can have up to five sort fields with BY HIGHEST or BY LOWEST.

Syntax: How to Restrict Sort Field Values by Highest/Lowest Rank

BY {HIGHEST n|LOWEST n} sortfield

where:

HIGHEST n

Specifies that only the highest n sort field values are included in the report. TOP is a synonym for HIGHEST.

LOWEST n

Specifies that only the lowest n sort field values are included in the report.

sortfield

Is the name of the sort field. The sort field can be numeric or alphanumeric.

Note: HIGHEST/LOWEST n refers to the number of sort field values, not the number of report rows. If several records have the same sort field value that satisfies the HIGHEST/LOWEST n criteria, all of them are included in the report.

Example: Restricting Sort Field Values to a Group

The following request displays the names of the employees earning the five highest salaries.

TABLE FILE EMPLOYEE
PRINT LAST_NAME
BY HIGHEST 5 CURR_SAL
END

The output is: