Progress
Programming
Handbook
Using Work Tables to Collect and Manipulate Data
Suppose that you want to add another step to the report shown in the previous section. In the new report, you want to:
To prepare this report without using work tables, you have to use variables to keep track of the item quantities as well as the item inventory values. The number of variables you need depends on the number of pages in the catalog. You might not know this number when you write the procedure. When you use work tables, you can store item quantities and inventory values in fields in the work table.
The numbers in the margin of the procedure correspond to the following activities:
- The DEFINE WORK–TABLE statement defines a work table, cpage, which contains four fields, w–cat–page (the work table catalog–page), w–inv–value (the work table inventory–value), w–item–value (the inventory value of a particular item), and w–item–num (the item number).
- For each of the records in the item table, the procedure checks whether there is a cpage record for the catalog page to which the item belongs. If there is not, the procedure creates a record and stores the cat–page value in the cpage record.
- If the value of the current item is greater than the value of any previous item for the same page, the ASSIGN statement stores the value and number of that item in the corresponding work table fields.
- This statement accumulates the inventory value for the catalog page.
- The FOR EACH block displays the inventory value of each page and the number and value of the highest value item on that page.
Using work tables allows you to sort on any value. For example, if you want to sort on the inventory value of the catalog pages, use the BY w–inv–value option on the FOR EACH block. Without work tables, you cannot do this sort as easily.
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |