Building the first B-trees

Once you have edited, compiled, and cataloged BTPINS and BTPKEY, you can create some initial B-trees for the NAMES file. This is accomplished by a small utility program that selects and reads each item in the NAMES file, and then passes each item to the BTPINS routine to insert the item in the B-tree for the first time. For example, here is a small utility program called BUILD that creates three B-trees for the NAMES file:

    BUILD
001 OPEN "B-TREE" TO BFILE ELSE STOP
002 OPEN "NAMES" TO NFILE ELSE STOP
003 SELECT NFILE
004 100 READNEXT ID ELSE STOP
005 READ ITEM FROM NFILE, ID ELSE STOP
006 CALL BTPINS("ZIP",  5, BFILE, NFILE, ID, ITEM)
007 CALL BTPINS("COMP", 5, BFILE, NFILE, ID, ITEM)
008 CALL BTPINS("LNAME",5, BFILE, NFILE, ID, ITEM)
009 GO TO 100
010 END

BUILD expects to find an empty file called B-TREE in which it will have BTPINS create the three B-trees. One B-tree is called ZIP, and keeps the NAMES sorted in ZIP code order. The second B-tree is called COMP, and keeps NAMES items sorted in company order. The last B-tree is called LNAME, and keeps NAMES items sorted by last name.

To actually create the three B-trees, first give the command CREATE-FILE B-TREE 1,1 7,1 to create the file where the B-trees will be kept. Then edit, compile, catalog and execute the BUILD program (since it's cataloged, just give the command BUILD to start the program) to actually build the B-trees.

Any error messages you encounter while executing BUILD are probably caused by not correctly copying one of the programs presented so far. Be sure that GET.NAMES, BTPINS, BTPKEY and BUILD have all been correctly edited, compiled, and cataloged.