Chapter 11
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