Chapter 8 – Data Validation

Slides:



Advertisements
Similar presentations
8-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Advertisements

Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
1 CSC103: Introduction to Computer and Programming Lecture No 8.
Objectives In this chapter, you will learn about:
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
Conditions What if?. Flow of Control The order of statement execution is called the flow of control Unless specified otherwise, the order of statement.
1 Selection Structures. 2 Making Decisions Sample assignment statements to figure worker pay with possible overtime PayAmount = Hours * Rate PayAmount.
C++ for Engineers and Scientists Third Edition
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
Chapter 9 IF Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
© 1999, by Que Education and Training, Chapter 5, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
Chapter 4: The Selection Structure
Programming Logic and Design Sixth Edition
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 6 Decisions and Conditions.
Chapter 5 Using Data and COBOL Operators. Initializing Variables When you define a variable in WORKING- STORAGE, you also can assign it an initial value.
Chapter 3 Making Decisions
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
Visual C# 2005 Decision Structures. Visual C# Objectives Understand decision making Learn how to make decisions using the if statement Learn how.
Selection Control Structures Simple Program Design Third Edition A Step-by-Step Approach 4.
1 Lecture 5: Selection Structures. Outline 2  Control Structures  Conditions  Relational Operators  Logical Operators  if statements  Two-Alternatives.
The DATA DIVISION Chapter 3. COBOL Data Organization Field - group of characters forming a meaningful unit or basic fact –Characters in a name or digits.
3-1 Chapter 3. To familiarize you with  Ways in which data is organized in COBOL  Rules for forming data-names  Defining input and output files in.
3-1 The DATA DIVISION Chapter Chapter Objectives To familiarize you with Systems design considerations Ways in which data is organized Rules for.
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
Lesson NUMERIC-FIELDPIC 9(5). 05 ALPHANUMERIC-FIELDPIC X(5).... IF NUMERIC-FIELD = 10...(valid entry) IF NUMERIC-FIELD = ‘10’... (invalid entry)
Edit Programs Please use speaker notes for additional information. Example: payedit.cbl payedit.cbl.
1 Boolean Expressions to Make Comparisons Boolean expression –Represents only one of two states –Expression evaluates to either true or false Expressions.
CHAPTER 4: Selection Control Structure. Objectives  Use the relational comparison operators  Learn about AND logic  Learn about OR logic  Make selections.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
More Syntax in COBOL  Moving Data  Selection Statements  System Date  Indicators in Display files.
Chapter 3 Decision Making. What is IF? The primary method of changing the flow of a program is by making decisions using the IF verb. The following example.
Chapter 5: Making Decisions
11- 1 Chapter 11.  Avoiding Logic Errors by Validating Input  What to Do If Input Errors Occur  Global Considerations in COBOL  When Data Should Be.
Chapter 8 Decision Making Using the IF and EVALUATE Statements.
The IF-statements 31-Jan-2005 Venkatesh Ramamoorthy.
1 Chapter 5 – The Procedure Division File handling statements –OPEN statement Initiates processing for a file Input Output Each file opened must have been.
Chapter 51 Logical Operators Used with Boolean expressions Not – makes a False expression True and vice versa And – will yield a True if and only if both.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
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?
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
An Object-Oriented Approach to Programming Logic and Design Chapter 5 Making Decisions.
11- 1 Chapter 11.  Avoiding Logic Errors by Validating Input  What to Do If Input Errors Occur  Global Considerations in COBOL  When Data Should Be.
Repetition Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 4 Making Decisions.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Chapter 4: Decisions and Conditions
LOGICAL CONTROL STRUCTURES (chp. 8)
Chapter 4: Decisions and Conditions
Sequence, Selection, Iteration The IF Statement
The Selection Structure
Chapter 4: Making Decisions.
Chapter 3 The DATA DIVISION.
Objectives After studying this chapter, you should be able to:
Iteration: Beyond the Basic PERFORM
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
Chapter 5 Decisions.
Chapter 3: Selection Structures: Making Decisions
Any Questions?.
The Selection Structure
Chapter 3: Selection Structures: Making Decisions
Decision Making Using the IF and EVALUATE Statements
Presentation transcript:

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

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

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

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-2 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). 05 ALPHANUMERIC-FIELD PIC X(5). . . . IF NUMERIC-FIELD = 10 . . . (valid entry) IF NUMERIC-FIELD = ‘10’ . . . (invalid entry) IF ALPHANUMERIC-FIELD = 10 (invalid entry) IF ALPHANUMERIC-FIELD = ‘10’ (valid entry) (b) Examples

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). 05 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

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

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

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

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

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

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

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

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

A data validation program Specifications Program design Program listing Exception report