Modifying the EMPLOYEE Program

One problem with your program is that there is no validation on the GENDER field. Clearly, only values of M and F should be allowed. GENDER would, ordinarily, be a Boolean field, with allowable values of M and F. It has been defined as a character field to provide a validation exercise. Consequently, with the program in its present form you could enter a meaningless value such as X or 3 in the GENDER field. The purpose of validation is to ensure that only meaningful values are entered. Fields are also validated by QA Build according to their type and their upper and lower limits, defined in MAKEDB.

Validating the GENDER field

1. Run the Program Editor, specifying SALESORD as the database and MYPROG2 as the program to edit. On the Procedure Tree diagram highlight EMP_UPDATE. In the Procedure Dialog select the Field Processing

2. A numbered list of EMPLOYEE fields is displayed. Use the mouse or cursor keys to highlight the GENDER field.

3. Select Edit Field. The processing for the GENDER field appears. The questions on this screen enable you to change the field processing. For example, if you wanted to display the contents of the field without allowing the user to modify it, you would change the answer for Input field ? from Yes to No.

4. To add validation, click on the option Validation condition. From the Formula Editing menu that pops up select Option 1 - Formula/Condition Nr. Press <Enter> to accept 1, the formula number suggested. [Check that this is as described]

5. To specify the validation condition, select Option 7 - Edit formula/condition. Another pop up appears, allowing for a formula of up to four lines, and including various questions. Type the condition:
employee.main.gender._ = "M" or "F"

6. Click on the option Remark on failure. QA Build can output a message if the condition is not met. Select Edit message to accept the proposed message number and to enter the Map Editor.

7. Add a static text control to the screen that is [one unit high and fifteen units long]. Double click on the control to bring up the Text Properties dialog then insert the following text for the caption:
Enter "M" (male) or "F" (female)
To add interest, you could also add a warning icon to the map and a suitable caption in the title bar.

8. Now add a button that can be clicked to clear the message when it has been read. Click on the Button icon or the Button choice under the Controls option in the menu bar. Move the button to the side of the message.

9. Now double-click on the button to adjust its properties. Firstly, change the caption to OK. Tick the Default Push Button box and make the Associated Key Press equal to <Esc>.

10. As you have added an input control, this needs to be specified on the main map properties dialog. Double click on an empty part of the map to bring up this dialog—change the field layout to rows 1, columns 1. Leave the Map Editor and save the map you have created.

11. You are returned to the window where you typed the condition. There are still three questions to address:
Warning only ?, More ? and Continue on failure ?

12. If Warning only ? is Yes, the user may decide to ignore the validation message after entering an invalid value. We want to force the user to enter a valid gender code, so accept the default answer, No.

13. A condition with more than one part can be specified in a single compound condition or its parts can be specified separately by responding Yes to the question More ? One benefit of separating the parts is that each can be given its own validation message. Your condition has one part, so press <Enter> to enter No.

14. Continue on failure ? is automatically answered as No and skipped, because there are no further parts to the condition. If there were, you could answer Yes. This forces QA Build to continue evaluating the condition in order to see whether other parts are also failing.

15. Click on OK to save your changes

16. Exit from the Program Editor

You can now recompile with the Program Compiler and run your program with the Interpreter. Check that any entry for GENDER other than M or F raises your error message, complete with button, and you are forced to re-input.