In sequential files, each data item is stored immediately following the previous one. The data in the file is stored in the order that it is produced. The data is read in the same order that it is stored. You read a sequential file from beginning to end. This results in a compact data storage structure and ease of programming.
The following example uses three files with sequential organization. The first two contain sorted data. They are merged to create the third file. Merging two files lends itself well to sequential organization.
10 REM Merge two sorted files
20 CREATE ASCII "merged",10
30 ASSIGN @F1 TO "file1";FORMAT ON
40 ASSIGN @F2 TO "file2";FORMAT ON
50 ASSIGN @M TO "merged";FORMAT ON
60 DIM Key1$[80],Key2$[80]
70 ON END @F1 GOTO Endf1
80 ON END @F2 GOTO Endf2
90 ENTER @F1;Key1$
100 ENTER @F2;Key2$
110 LOOP
120 IF Key1$>Key2$ THEN
130 OUTPUT @M;Key2$
140 ENTER @F2;Key2$
150 ELSE
160 OUTPUT @M;Key1$
170 ENTER @F1;Key1$
180 END IF
190 END LOOP
200 Endf1:! only file2 has any more data
210 ON END @F2 GOTO Alldone
220 LOOP
230 OUTPUT @M;Key2$
240 ENTER @F2;Key2$
250 END LOOP
260 Endf2:! only file1 has any more data
270 ON END @F1 GOTO Alldone
280 LOOP
290 OUTPUT @M;Key1$
300 ENTER @F1;Key1$
310 END LOOP
320 Alldone:! both files are out of data
330 ASSIGN @F1 TO *
340 ASSIGN @F2 TO *
350 ASSIGN @M TO *
360 END
|