0% found this document useful (0 votes)
55 views

Chapter 11

The document discusses the importance of validating input data to ensure accuracy and prevent errors, describes various techniques for validating data such as checking for correct formats, missing data, and reasonableness of values, and outlines actions that can be taken if input validation detects errors like printing error messages or stopping the program run.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Chapter 11

The document discusses the importance of validating input data to ensure accuracy and prevent errors, describes various techniques for validating data such as checking for correct formats, missing data, and reasonableness of values, and outlines actions that can be taken if input validation detects errors like printing error messages or stopping the program run.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 16

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
1. Test fields for correct format
NUMERIC or ALPHABETIC
Sign test
2. Checking for missing data
3. INSPECT statement
4. Testing for reasonableness
Checking for missing data
• Check key fields if they must contain data
Example

If Soc-Sec-No = Spaces
Perform 900-Err-Rtn
End-If
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
Examples
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

Fields Results
X1 = bb82b Ct1 = 3
X2 = AB32C Ct2 = 5
X3 = 00060 Ct3 = 3
INSPECT … REPLACING
• To replace specified occurrences of a
given character with another
INSPECT … REPLACING
Examples

Inspect Date-In Replacing All '-' By '/'


Inspect SSNo Replacing All Spaces By '-'

Field Before After


Date-In 10-17-02 10/17/02
SSNo 123 45 6789 123-45-6789
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
1. Print error record displaying key field,
field in error and error message
2. Stop the run to preserve data integrity
3. Partially process or bypass erroneous
records
4. 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
6. 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

You might also like