5.11 Validate and Lookup

Form can verify that the data entered into a field is a valid record in another RMSfile. Specifying a validation RMSfile on the Field Description form requires that the data entered into the field be a valid key in another RMSfile. The RMSfile to be used for validation is named in the Validation File field. When the user exits a screen field that has a validation file specified and the screen field contains data, form reads the validation file using the screen field contents as the key value. If there is no such record in the validation file, form displays an error message. If a record is found with a key value equal to the field contents, form saves a copy of that record in an internal buffer.

Form can also display one or more data field values from the record saved by the validation. To do so, an additional field is created on the data entry screen for each field to be displayed from the saved record. In these fields, the lookup field in the Field Description form gives the data field name in the validation RMSfile that is to be displayed on the screen. Normally, these fields have both Entry Allowed and In Data File set to no. This places a field on the screen, but the screen field does not represent a data field in the current data record. The field is displayed as an underlined field to show that the field value cannot be changed.

If a validation or lookup field has In Data File set to yes, the data type and size of that field in the current form's RMSfile must exactly match the data type and size of the corresponding field in the validation RMSfile.

To demonstrate validation and lookups, we will add another field on the screen next to the magazine data entry field. This new field is used to display the magazine title. A revised data entry screen would look like:

gifs/00000001.gif

The screen below shows the modified subscriber Field Description form. The subscriber RMSfile name has been added to the Validation File field. Now each time the operator exits the subscriber field, its contents is validated with the subscriber RMSfile.

gifs/00000001.gif

When data is entered into the subscriber field, it is used to look up a record in the subscriber RMSfile. If a record with that key is in the subscriber RMSfile, then the data entered into the field is valid. If there is no record in the subscriber RMSfile with that key value, form displays an error message and returns the cursor to the beginning of the subscriber field. The user must enter a valid subscriber or clear the entire field to be able to exit from the subscriber field.

The screen below shows the modified magazine Field Description form. It also has a validation file name added, so the magazine field contents is compared with the magazine RMSfile.

gifs/00000001.gif

When data is entered into the magazine field, it is used to look up a record in the magazine RMSfile. Again, if a record with that key value is not there, form displays an error message; otherwise, the data entered is valid.

gifs/00000001.gif

The screen above shows the Field Description of the new field that was added to the data entry screen. It displays the contents of the title field from the magazine data record. Recall that every time a field validation is performed, form saves a copy of the record that was read. If a lookup field is specified, form fetches a data field value out of the saved record. In this example, form fetches the title field contents from the magazine data record that was read when validating the magazine field and displays the magazine title on the screen.

In the example above, the lookup field is used only once. But it is possible to look up several fields from the same validation record. All the lookup fields associated with a particular validation field must follow after the screen field that performs the validation. It is also possible to do several validations in one form and perform lookups after each validation. To demonstrate this, one additional feature will be added to the subscription data entry screen. Each time the subscriber field is validated, the subscriber name and address is also displayed.

gifs/00000001.gif

This involves only adding additional lookup fields. These fields would be entered as in the screen above. Each new field would have the Lookup Field field filled in with the name of the field from the subscriber RMSfile to be displayed. Now each time a subscriber code is entered, the subscriber's name and entire address are displayed on the screen. As before, when a magazine code is entered, the magazine title is displayed. Of course, changing one of the validated fields changes only the lookup fields associated with it.

Note that each field used for lookups does not contain a data field name in the Field Description form. Also, the In Data File field is set to no. The lookup field on the screen is not associated with a data field in the subscription RMSfile, and so no field name is entered. Also note that no validation file is specified for any of the lookup fields. Form assumes that the RMSfile used for performing lookups is the validation file used in the last previously validated field.

The screen shown above is distributed with the C/Base demonstration system. It is not displayed from any of the menu choices, but you may inspect it by using toolkit to examine the formfile named script.