1 Introduction
Here is the same program shown earlier, but with some additional statements filled in:
In this example, lines 80 thru 100 are used to create a file, ASSIGN it to a file position and convert it into a workfile. (Note that the file is still of type DATA.) Line 120 produces pointers so the data can be accessed in sorted order. Line 170 reads the pointer into an Eloquence variable so it can be used in the direct mode DBGET in line 180.
One additional function has been introduced in this example, the WFLEN function used in line 130. This function returns the number of pointers in the workfile. It has as an argument, the file number of the workfile, since more than one workfile may be in use at a given time. Notice that the program creates and purges the workfile each time the program is run. If disk space is available, program execution time can be decreased by deleting lines 80 and 220, which allows the file to remain on the disk.
10 DIM Buf$[170],B$[5],Order_no$[10],Name$[30] 20 INTEGER S(9) ! Ten-element status array. 30 B$=" SAD" 40 DBOPEN (B$,"MANAGER",3,S(*)) ! Open the database. 50 DBASE IS B$ 60 IN DATA SET "CUSTOMER" USE Order_no$,Name$ 70 ! Now set up a workfile with CUSTOMER as the thread. 80 FCREATE "XYZ" ,0 90 ASSIGN "XYZ" TO #1 100 WORKFILE IS #1;THREAD IS "CUSTOMER" 110 ! Sort the orders by order number. 120 SORT BY Order_no$ 130 Entry_count=WFLEN(1) !WFLEN returns no of pointers in file. 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. 170 READ #1;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(*)) 220 PURGE "XYZ" 230 END