160 likes | 175 Views
Chapter 11. Data Validation. Question. Should your program assume the data is correct, or should your program edit the data to ensure it is correct?. Why Input Must Be Validated. Risk of data entry errors is high Large volume of data entered Human error keying in data
E N D
Chapter 11 Data Validation
Question • Should your program assume the data is correct, or should your program edit the data to ensure it is correct?
Why Input Must Be Validated • Risk of data entry errors is high • Large volume of data entered • Human error keying in data • Invalid input leads to inaccurate output • For example, salary reported incorrectly if entered as 23000 instead of 32000 • Input error can cause program interrupt • For example, spaces entered for numeric field used in arithmetic operation
Data Validation Techniques • Routines to identify various types of input errors • Error modules to handle each error that occurs
Data Validation Techniques • Test fields for correct formatNUMERIC or ALPHABETICSign test • Checking for missing data • INSPECT statement • Testing for reasonableness
Checking for missing data • Check key fields if they must contain data If Soc-Sec-No = Spaces Perform 900-Err-Rtn End-If Example
INSPECT Statement • Useful for validity checking as well as other purposes • Two main functions • To count number of occurrences of given character in field • To replace specific occurrences of given character with another character
INSPECT … TALLYING Move Zeros To Ct1, Ct2, Ct3 Inspect X1 Tallying Ct1 For All Spaces Inspect X2 Tallying Ct2 For Characters Inspect X3 Tallying Ct3 For Leading Zeros FieldsResults X1 = bb82b Ct1 = 3 X2 = AB32C Ct2 = 5 X3 = 00060 Ct3 = 3 Examples
INSPECT … REPLACING • To replace specified occurrences of a given character with another
INSPECT … REPLACING Inspect Date-In Replacing All '-' By '/' Inspect SSNo Replacing All Spaces By '-' FieldBeforeAfter Date-In 10-17-02 10/17/02 SSNo 123 45 6789 123-45-6789 Examples
Testing for Reasonableness • Use after verifying that numeric fields contain numeric data • Range test - check that field is within established lower and upper bounds • Limit test - check that field does not exceed defined upper limit
Actions If Input Errors Occur • Print error record displaying key field, field in error and error message • Stop the run to preserve data integrity • Partially process or bypass erroneous records • Stop the run if number of errors exceeds predetermined limit
Actions If Input Errors Occur 5. Use switch or field to indicate when record contains error • Initialize field to 'N' for no errors • Set field to 'Y' anytime an error occurs • Process record as valid only if switch field still 'N' after all validation checks
Actions If Input Errors Occur • Print count totals and compare to manual counts • Print count of all records processed • Print count of all errors encountered • Print batch totals or count of all records within specific groups or batches