Progress
Programming
Handbook
Using Work Tables for Complex Sorting
Progress uses indexes to order database records. Although work tables have no indexes, you can position work table records where you want because whenever you create a work table record, Progress places it after the record that it found last in that work table. This flexibility lets you keep the work table records in a particular order without having to sort later in the procedure. For example,
p-wrk4.p
is a modified version of thep-wrk3.p
procedure:
This procedure uses the following logic to maintain the cpage work table in catalog page order:
- The FIND FIRST statement tries to find a cpage record whose catalog page is the same or greater than that of the current item.
- If the catalog page of the cpage record is larger than that of the current item, or if the cpage record does not exist, Progress finds the previous cpage record (if any) and creates the new cpage record after that record in the work table. If it finds a cpage record with the same product line as the item, it does not create a new cpage record, but uses the existing one.
- The procedure computes the necessary field values for the current cpage record.
Figure 15–3 shows how this procedure keeps the cpage work table in order by product line.
Figure 15–3: Maintaining Work Tables in Sorted Order
![]()
By maintaining the cpage table in catalog page order as the procedure creates new cpage records, there is no need to sort the table in the final FOR EACH block. When that block displays the cpage records, they are already sorted by catalog page.
There is another advantage to using this method of sorting as opposed to the method used in
p-wrk3.p.
Figure 15–4 illustrates this advantage.p-wrk3.pp-wrk4.pFigure 15–4: Comparing Two Sorting Methods
![]()
In Method 2, because the records in the cpage table are already in sorted order, the find is much more efficient than in Method 1. For an item with a catalog page that already exists in the cpage table, both methods are equally efficient, on average.
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |