4.8 Example 2: Modify an Existing File Definition

You can modify the definition of an existing RMSfile with lfedit as well as to create a new RMSfile. In this example, we will make the following changes to the RMSfile we created in Example 1:

gifs/20000000.gif Change the File Access Method to indexed.

gifs/20000000.gif Add a new field named publisher (to contain the name of the company that publishes the magazine) as a 36 character string field.

gifs/20000000.gif Delete the year_rate field.

gifs/20000000.gif Change the Data Type of the subscribers field to real.

gifs/20000000.gif Add an array field named rates which is made up of 3 money values (rates for 1, 2, and 3 year subscriptions).

gifs/20000000.gif Add a Secondary Key defined as the 'concatenation' of the publisher and title fields.

To begin modifying the definition of the logical RMSfile mydb~mag that was created in Example 1, enter:

c:\>lfedit mydb~mag

You should see the first File Definition form as shown below:

gifs/00000001.gif

Notice that the ADD function is no longer allowed. Instead, you can modify the data on the form by pressing the UPDATE key. Perform the following steps to change the File Access Method:

gifs/20000000.gif Press the UPDATE key to modify the File Access Method

gifs/20000000.gif Press the CLEAR key to clear the old values from the form

gifs/20000000.gif Press i followed by the RETURN key to select the indexed File Access Method

gifs/20000000.gif Press the RETURN key to select the default Primary Key Ordering

gifs/20000000.gif Press the RETURN key to select the default Duplicate Key Handling

gifs/20000000.gif Press the STORE key to record the changes you have made

The screen should now appear as follows:

gifs/00000001.gif

Press the SWITCH key to display the Field Descriptions form (along with the contents of the first Field Description) as shown:

gifs/00000001.gif

You may update or delete existing fields, as well as add new fields, on this form. To add a field, press the ADD key and a blank Field Description form is appended, provided that the current form is not already blank. Before updating or deleting a Field Description, you must first 'locate' it (i.e., position it in, or bring it into, the current form). Press the PREVIOUS and NEXT keys to locate a particular field. Press the STORE key to record any updates or additions, however it is unnecessary when deleting fields.

Our first entry on this form is to add the new field, publisher, after the magazine field. A common error is to simply select the ADD function immediately and then enter and store the information for the new field. This, however, would cause the alias name key (which was added in Example 1 of this chapter) to no longer refer to the magazine field, but rather to the new field, publisher. As a safeguard against this error, strict adherence to the following procedure is strongly recommended:

1. Repeatedly press the NEXT key to locate the first non-alias Field Description (the screen should appear as shown below):

gifs/00000001.gif

1. Press the PREVIOUS key once so that the current form contains the Field Description immediately preceding the one which was located in Step #1 (as shown below):

gifs/00000001.gif

1. You may now add the new Field Description.

After pressing the ADD key, the screen should appear as shown below:

gifs/00000001.gif

Enter the information for the publisher field as outlined in the beginning of Example 2. After pressing the STORE key to record this Field Description the screen should appear as shown:

gifs/00000001.gif

Although it is possible to enter additional new Field Descriptions at this time, the next item on our list of changes is to delete a field. Therefore, to continue with this example in step-by-step fashion, you must first press the CANCEL key to cancel ADD mode (which is currently still active) before proceeding further.

To delete the year_rate field, first locate it by pressing the NEXT key repeatedly until the year_rate field appears. Once the year_rate field has been located, press the F1 then <D> to remove it. The following display shows how the screen should look after the year_rate field has been deleted:

gifs/00000001.gif

Pressing the NEXT function displays the next field, subscribers, in the current blank form. (Note: Had the year_rate field had any alias names associated with it, they would have followed it in appearance sequentially, in which case it would have been necessary to delete them, one by one, by pressing the DELETE key <F1>-D ).

Press the UPDATE key to change the definition for the subscribers field. Press the Tab key to move the cursor to the start of the Data Type field. To change the Data Type to real, press the Kill key to clear the field, enter an r and press RETURN. The field now shows the new Data Type value of real. The cursor should now be in the Field Length field. The number in this field was the size of an integer field, which might not be valid for a real field. You may use either the Kill key or the Space bar (by 'spacing-over' the field contents) to clear this value. Press the RETURN key to select the default Field Length value for the real data type. The screen should now appear as below:

gifs/00000001.gif

To record these changes, press the STORE key.

Now enter the new field, rates. After pressing the ADD key, the screen should appear as follows:

gifs/00000001.gif

The rates Field Description entry should look like that of the former year_rate field, except that the Number of Elements field should be set to a value of 3. After this field has been entered and stored, the screen should appear as follows:

gifs/00000001.gif

When all of the Field Description entries have been completed, press the SWITCH key to display the Primary Key Field Names form as shown below:

gifs/00000001.gif

Since a Primary Key has already been defined, ADD is no longer allowed. The UPDATE function allows changes to be made to the Primary Key, and the STORE function records these changes.

Press the SWITCH key to display the form for defining Secondary Key Field Names as shown below:

gifs/00000001.gif

At this point, you can change or delete the current secondary index, add more indexes or 'step through' the indexes. To add a new Secondary Key on the publisher and title fields press the ADD key. After you enter the field names publisher and title into the first and second fields, respectively, press the STORE key to store the Secondary Key definition.

Since this is a repeating form, a new form is appended as shown below:

gifs/00000001.gif

At this point, you may add new Secondary Key definitions, update or delete existing Secondary Key definitions (after having 'located' them), switch back to the File Definition form to make additional modifications, or exit from the definition process. Prior to selecting this last option (which must be performed before you can continue beyond this example), we should look once more at the Field Descriptions form in order to illustrate a potential problem which new C/Base software users often experience.

To do so, press the SWITCH key <F7>. The screen should appear as follows:

gifs/00000001.gif

Press the SWITCH key <F7> again to display the Field Descriptions form as shown below:

gifs/00000001.gif

Repeatedly press the NEXT key to display all of the current Field Descriptions until the No more fields message is displayed. The screen should now appear as the following:

gifs/00000001.gif

If you press the ADD key at this point to add new Field Descriptions, they would be added not at the end of the field list, but at the beginning. This may cause conflicts with C programs which access the fields of the RMSfile by means of this list. A problem would also arise if the Field Description being added was an alias-name, in that it would refer not to the last Field Description of the field list, but to no Field Description whatsoever, as it (i.e., the alias) would be the first Field Description in the field list. Therefore, in order to avoid any potential conflicts, press the PREVIOUS key to reposition the 'pointer' at the end, rather than at the beginning, of the field list before adding any new Field Descriptions. The screen would then appear as shown below:

gifs/00000001.gif

You may now press the EXIT key to continue with the remainder of this chapter.