The following programs demonstrate the use of the SORT clause
using the default sort order, ascending. These programs:
o Sort the records in CURRENT_INFO using SALARY as the sort key
o Sort in ascending order because no sort order is specified
o Print the last names and salaries stored in the sorted records
1 – C Example
#include <stdio.h>
DATABASE PERS = FILENAME "PERSONNEL";
main()
{
READY PERS;
START_TRANSACTION READ_ONLY;
FOR CI IN CURRENT_INFO
SORTED BY CI.SALARY
printf ("%s $%f\n",CI.LAST_NAME, CI.SALARY);
END_FOR;
COMMIT;
FINISH;
}
2 – Pascal Example
program sort_single_field (input,output);
DATABASE PERS = FILENAME 'PERSONNEL';
begin
READY PERS;
START_TRANSACTION READ_ONLY;
FOR CI IN CURRENT_INFO
SORTED BY CI.SALARY
writeln (CI.LAST_NAME, ' $', CI.SALARY :10:2);
END_FOR;
COMMIT;
FINISH;
end.