How to modify BTPKEY

The examples presented earlier used three different B-trees for sorting items in the NAMES file in three different ways. The B-tree named ZIP sorted items by ZIP code by address by company by last name by first name by ID. (In other words, by attribute 6 by attribute 4 by attribute 3 by attribute 2 by attribute 1 by ID.) As a result, the BTPKEY subroutine required the following code:

KEY = ITEM<6>:nul:ITEM<4>:nul:ITEM<3>:nul:ITEM<2>:nul:ITEM<1>:nul:(ID"R#10")

The COMP B-tree sorted by company by last name by first name by ID (by 3 by 2 by 1 by ID), so BTPKEY included the statements:


Finally, the LNAME B-tree sorted items by last name by first name by ID (by 2 by 1 by ID), so BTPKEY included:

KEY = ITEM<2>:nul:ITEM<1>:nul:(ID "R#10")

Two statements like each of the above examples must be included in the BEGIN CASE/END CASE section of the BTPKEY subroutine for every B-tree you decide to use. Adding such statements and recompiling BTPKEY (some Pick systems may also require recataloging), is the only adjustment that ever needs to be made to any of the B-TREE-P subroutines in order to work with any data files.

The first statement of the pair added to BTPKEY is always of the form CASE ROOT = name, where name is the quoted name of the B-tree being added. The second statement is always of the form KEY = expression, where expression is an ordered concatentation of subexpressions representing the various sort fields being used. Note that :nul: always separates each subexpression from the next.

A sort field may be represented by any valid BASIC expression, not just attribute extraction. For example, assume payroll items are being sorted by total income by name by Social Security number (the ID). If total income is computed by subtracting attribute 7 of the payroll item from attribute 5, with the name in attribute 2, then the necessary BTPKEY statements for a B-tree named PAYROLL would be:

KEY=((ITEM<5>-ITEM<7>) "R#10"):nul:ITEM<2>:nul:ID

Note that a right-justified numeric sort is desired for the total income field (as opposed to a default left-justified alphabetic sort), so "R#10" is appended to the calculation for that field. (Although right justification was also used for the numeric ID numbers in the other examples, these payroll ID numbers are alphanumeric Social Security numbers all of the same length, so default left-justified sorting is good enough, just like for five-digit ZIP codes.) When specifying right justification with R#x, be sure x is as wide as the widest possible result for that field.

Every BTPKEY sort specification must use ID somewhere after KEY=, even if ID is only tacked on the end of the sort fields to provide a final default sort like Pick's own SORT command. Otherwise, the other B-TREE-P subroutines will not operate correctly.