Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 8 – Data Validation

Similar presentations


Presentation on theme: "Chapter 8 – Data Validation"— Presentation transcript:

1 Chapter 8 – Data Validation
Incoming data must be check to avoid errors Numeric test Alphabetic test Reasonableness check Limit/Range checks – number is within limits Consistency check Comparing two fields against eachother

2 Existing code check Sequence check Completeness check Date check
Omission errors – full statements in your IFs Sequence check Incoming records are in the correct order Completeness check Makes sure that all the fields in any record contain data Date check Checks that incoming date is logical

3 The IF statement Relational condition Class test Sign test
NUMERIC clause ALPHABETIC clause Sign test POSITIVE clause NEGATIVE clause ZERO clause

4 Figure 8.1 The Relational Condition
IS [NOT] GREATER THAN IS [NOT] > IS [NOT] LESS THAN identifier-1 IS [NOT] < identifier-2 IF literal-1 IS [NOT] EQUAL TO literal expression-1 IS [NOT] = expression-2 IS [NOT] GREATER THAN OR EQUAL TO IS [NOT] >= IS [NOT] LESS THAN OR EQUAL TO IS [NOT] <= (a) Syntax 05 NUMERIC-FIELD PIC 9(5) ALPHANUMERIC-FIELD PIC X(5) IF NUMERIC-FIELD = (valid entry) IF NUMERIC-FIELD = ‘10’ (invalid entry) IF ALPHANUMERIC-FIELD = 10 (invalid entry) IF ALPHANUMERIC-FIELD = ‘10’ (valid entry) (b) Examples

5 Figure 8.2 The Class Test (a) Syntax (b) Examples
NUMERIC ALPHABETIC IF identifier IS [NOT] ALPHABETIC-UPPER ALPHABETIC-LOWER (a) Syntax 05 NUMERIC-FIELD PIC 9(5) ALPHABETIC-FIELD PIC X(5) IF NUMERIC-FIELD IS NUMERIC PERFORM D0-ARITHMETIC-CALCULATIONS END-IF. IF NUMERIC-FIELD IS NOT NUMERIC DISPLAY ‘ERROR - NUMERIC FIELD CONTAINS INVALID DATA’ END-IF. IF ALPHABETIC-FIELD IS ALPHABETIC DISPLAY ‘ALPHABETIC FIELD CONTAINS UPPER AND/OR LOWER CASE LETTERS’ END-IF. IF ALPHABETIC-FIELD IS NOTALPHABETIC DISPLAY ‘ERROR - ALPHABETIC FIELD CONTAINS NON-ALPHABETIC DATA’ END-IF. (b) Examples

6 Figure 8.3 The SignTest (a) Syntax (b) Examples
identifier POSITIVE IF arithmetic expression IS [NOT] NEGATIVE ZERO (a) Syntax IF NET-PAY IS NOT POSITIVE PERFORM TOO-MUCH-TAXES END-IF. IF CHECK-BALANCE IS NEGATIVE PERFORM OVERDRAWN END-IF. (b) Examples

7 Compound test Operators Precedence of operators Implied conditions
AND expression OR expression NOT expression Precedence of operators Arithmetic, Relational, NOT, AND, OR Effect of parenthesis Implied conditions IF TERM > 6 and TERM < 12 THEN IF TERM > 6 AND < 12 THEN

8 Figure 8.5 Compound Conditions
C>D? FALSE TRUE A>B? NO YES FALSE C>D? TRUE A>B? NO YES (a) A > B AND C > D (b) A > B OR C > D

9 Comparing a Date to Today’s date
Nested IF statements ELSE clause Comparing a Date to Today’s date

10 Figure 8.6 Nested IF Statements
A>C? MOVE C TO BIG MOVE A TO BIG A>B? NO YES C>B? MOVE B TO BIG (a) Flowchart

11 Figure 8.6 Nested IF Statements
IF A > B IF A > C MOVE A TO BIG ELSE MOVE C TO BIG END-IF ELSE IF C > B MOVE C TO BIG ELSE MOVE B TO BIG END-IF END-IF. (b) COBOL Statements

12 Figure 8.8 The ACCEPT Statement
WORKING-STORAGE SECTION. 01 EMPLOYEE-RECORD EMP-DATE-OF-BIRTH EMP-BIRTH-MONTH PIC EMP-BIRTH-YEAR PIC 99. 01 EMPLOYEE-AGE PIC 99V99. 01 DATE-WORK-AREA TODAYS-YEAR PIC TODAYS-MONTH PIC TODAYS-DAY PIC PROCEDURE DIVISION ACCEPT DATE-WORK-AREA FROM DATE COMPUTE EMPLOYEE-AGE = TODAYS-YEAR - EMP-BIRTH-YEAR + (TODAYS-MONTH - EMP-BIRTH-MONTH) / 12.

13 Figure 8.10 (continued) (b) Error Report ERROR REPORT AS OF 07/03/98
CONTRACT # LAST NAME ERROR MESSAGE & FIELD CONTENTS BAKER INVALID DAY 04/ BAKER INSURANCE CODE MUST BE Y OR N X BROWN MILES DRIVEN UNREASONABLY LOW DAYS: 10 MILES: JONES MONTH MUST BE BETWEEN 1 AND JONES MILEAGE IN LESS THAN MILEAGE OUT IN: OUT: JONES NON-NUMERIC MILEAGE RATE O5 BROWNING CAR TYPE MUST BE: E, C, M, F, OR L BROWNING DATE HAS NOT YET OCCURRED 10/24/ BROWNING NON-NUMERIC MILES IN OO2400 FITZPATRICK INVALID DAY 05/ FITZPATRICK INSURANCE CODE MUST BE Y OR N C PINNOCK NON-NUMERIC CONTRACT NUMBER PINNOCK MISSING FIRST NAME PINNOCK NON ALPHABETIC INITIAL PINNOCK DATE YAS NOT YET OCCURRED 10/12/ PINNOCK NON-NUMERIC MILES OUT OO3310 X BUTLER NON-NUMERIC CONTRACT NUMBER X X BUTLER INVALID DAY 06/31 X BUTLER DAYS RENTED MUST BE > ZERO X BUTLER MILEAGE RATE OUT OF RANGE 75 84644O NON-NUMERIC CONTRACT NUMBER 84644O O MISSING LAST NAME O CAR TYPE MUST BE: E, C, M, F, OR L X O DAYS RENTED MUST BE NUMERIC I O MILES DRIVEN UNREASONABLY LOW DAYS: I5 MILES: (b) Error Report

14 A data validation program
Specifications Program design Program listing Exception report


Download ppt "Chapter 8 – Data Validation"

Similar presentations


Ads by Google