1 Introduction

The Workfile

With SORT you create a specific access sequence to the database. You do not actually change the sequence of the data in the data base itself. What you do is to build a series of pointers to the various records of each set in the thread. These pointers are stored in a special file called the workfile and can be used with direct-mode DBGETs to extract information from the database. If, for example, you want to produce a report listing all orders plus the company placing each order (see the next report), you could use a program like the one shown next. This program opens the Sales Analysis database, sets up a workfile, sorts the data by order number and prints the results. (Note that the order shown in the sample run below is, in fact, correct since the items being stored are strings, not numerics).

   10    DIM Buf$[170],B$[5],Order_no$[10],Names$[30]
   20    INTEGER  S(9)                 ! Ten-element status array.
   30    B$="SAD"
   40    DBOPEN (B$,"SECRET",3,S(*))   !   Open the database.
   50    DBASE IS B$
   60    IN DATA SET "CUSTOMERS" USE Order_no$,Name$
   70    !  Now set up a workfile with CUSTOMER as the thread.
            .
            .
            .
   110   !  Sort the orders by order number.
            .
            .
   140   PRINT " ORDER NUMBER";TAB(30);"CUSTOMER NAME";LIN(2)
   150   FOR I=1 TO Entry_count
   160     ! Read the record pointer into Rec_no.
            .
   180     DBGET (B$,"CUSTOMER",4,S(*),"@",Buf$,Rec_no)
   190     PRINT Order_no$;TAB(30);Name$
   200   NEXT I
   210   DBCLOSE (B$," ",1,S(*))
            .
   230   END


   RUN
   ORDER NUMBER                        CUSTOMER NAME

   10                                  ABC Company
   100                                 Colorado Feed and Grain
   12.6                                Bruce's Bar & Grill
   17.2                                Timmy's Pet Store
   20                                  ABC Company
   999                                 Internal Revenue Service
In many respects, the workfile is just like a regular data file. It must be CREATEd and ASSIGNed just like a DATA file. Only its use in the program distinguishes it as a workfile. After the program defines a file as a workfile, it remains that way until either it is de-ASSIGNed or the program stops. Since the workfile is so similar to a normal data file, most of the standard file operations work on it. Record pointers are read from the workfile with the READ # statement, and pointers may be added to it using PRINT #. The next figure shows how the contents of the workfile are related to the base entries used in the previous example.

Figure 2 Data Base/Workfile Relationship


Eloquence Sort Manual - 19 DEC 2002