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.

Slides:



Advertisements
Similar presentations
DT266/2 Information Systems COBOL Revision. Chapters 1 & 2 Hutty & Spence Divisions of a Cobol Program Identification Division Program-ID. Environment.
Advertisements

Intermediate Code Generation
12-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
Chapter 12 Array Processing and Table Handling. Defining Series of Input Fields Coding record with 24 independent hourly fields is cumbersome 01Temp-Rec.
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)
Programming Logic and Design Sixth Edition
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
C++ for Engineers and Scientists Third Edition
Guide To UNIX Using Linux Third Edition
Chapter 7. 2 Objectives You should be able to describe: The string Class Character Manipulation Methods Exception Handling Input Data Validation Namespaces.
Introduction to C Programming
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
Advanced Shell Programming. 2 Objectives Use techniques to ensure a script is employing the correct shell Set the default shell Configure Bash login and.
Topics Covered: Data preparation Data preparation Data capturing Data capturing Data verification and validation Data verification and validation Data.
12-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
12-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)
Chapter To familiarize you with  Why COBOL is a popular business-oriented language.  Programming practices and techniques  History of COBOL.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
12- 1 Chapter 12.  Single-Level OCCURS Clauses  Processing Data Stored in Array  Using OCCURS Clause for Table Handling  Use of SEARCH Statement 
CNG 140 C Programming (Lecture set 9) Spring Chapter 9 Character Strings.
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.
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
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.
1 Interactive vs Batch Programs Cobol suited for developing both types of programs Interactive programs Accept input data from keyboard Input data processed.
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
Chapter 12 (part 2) Table Handling and Search Techniques.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 5 Arrays.
Lesson NUMERIC-FIELDPIC 9(5). 05 ALPHANUMERIC-FIELDPIC X(5).... IF NUMERIC-FIELD = 10...(valid entry) IF NUMERIC-FIELD = ‘10’... (invalid entry)
Indexed and Relative File Processing
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Edit Programs Please use speaker notes for additional information. Example: payedit.cbl payedit.cbl.
13-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)
Sequential Files Chapter 13. Master Files Set of files used to store companies data in areas like payroll, inventory Set of files used to store companies.
9-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)
9-1 Iteration: Beyond the Basic PERFORM Chapter 9.
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.
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.
12- 1 Chapter 12.  Single-Level OCCURS Clauses  Processing Data Stored in Array  Using OCCURS Clause for Table Handling  Use of SEARCH Statement 
Chapter 8 Decision Making Using the IF and EVALUATE Statements.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 8 Arrays.
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 8 – Data Validation
Verification & Validation. Batch processing In a batch processing system, documents such as sales orders are collected into batches of typically 50 documents.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
13-1 Sequential File Processing Chapter Chapter Contents Overview of Sequential File Processing Sequential File Updating - Creating a New Master.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
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?
13- 1 Chapter 13.  Overview of Sequential File Processing  Sequential File Updating - Creating a New Master File  Validity Checking in Update Procedures.
12-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)
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 6 Arrays.
16- 1 Chapter 16.  To familiarize you with  COPY statement for copying parts of a program stored in a library  CALL statement for executing called.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
A First Book of C++ Chapter 4 Selection.
LOGICAL CONTROL STRUCTURES (chp. 8)
The Selection Structure
Designing and Debugging Batch and Interactive COBOL Programs
Chapter 3 The DATA DIVISION.
An Introduction to Structured Program Design in COBOL
Chapter 14 Sorting and Merging.
Iteration: Beyond the Basic PERFORM
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Programming Logic and Design Fifth Edition, Comprehensive
Decision Making Using the IF and EVALUATE Statements
CHAPTER 6 Testing and Debugging.
Presentation transcript:

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 Validated  Understanding Program Interrupts  Other Methods for Improving Program Performance 11- 2

 For every IF statement, use test data that satisfies and does not satisfy condition  For multi-page report include enough test data to print several pages  Include test data that produces size errors if ON SIZE ERROR routines are used 11- 3

 Use DISPLAY statements during test runs to isolate logic errors  If program produces disk file, always examine it for accuracy  Check loops to see that instructions performed exact number of times required  Compile often 11- 4

 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 instead of  Input error can cause program interrupt ◦ For example, spaces entered for numeric field used in arithmetic operation 11- 5

 Routines to identify various types of input errors  Error modules to handle each error that occurs 11- 6

 Use NUMERIC class test to ensure field used in arithmetic operation has numeric value If Amt-In Is Not Numeric Perform 500-Err-Rtn Else Add Amt-In To WS-Total End-If Example

 Use ALPHABETIC class test if field must be alphabetic  COBOL has built in functions for the following: ◦ Values greater than zero (POSITIVE) ◦ Values less than zero (NEGATIVE) ◦ Value equal to zero (ZERO)  S must be included in PIC to store a negative number  NOT POSITIVE is not same as NEGATIVE ◦ IF X IS POSITIVE THEN … 11- 8

 Check key fields if they must contain data If Soc-Sec-No = Spaces Perform 900-Err-Rtn End-If Example

 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

 To count number of times a given character occurs INSPECT identifier-1 TALLYING ALL identifier-3 identifier-2 FOR LEADING literal-1 CHARACTERS Format

 identifier-1 ◦ Field to be "inspected"  identifier-2 ◦ Field where count stored ◦ Not automatically set to zero by INSPECT  identifier-3 or literal-1 ◦ Character to be counted ◦ ZERO, SPACE, 8, 'S' are valid entries for literal

 ALL - every occurrence of specified character in field counted  LEADING - all occurrences of specified character preceding any other character tallied  CHARACTERS - all characters within field tallied ◦ Used to determine size of field

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 = bb82bCt1 = 3 X2 = AB32CCt2 = 5 X3 = 00060Ct3 = Examples

 Optional clause after FOR options to count only characters before or after some initial value BEFOREINITIALidentifier-4 AFTERliteral Format

Move Zeros To Ct4, Ct5 Inspect X4 Tallying Ct4 For All Zeros Before Initial 9 Inspect X5 Tallying Ct5 For Characters After Initial 6 ItemsResults X4 = 05090Ct4 = 2 X5 = 06762Ct5 = Examples

 To replace specified occurrences of a given character with another INSPECT identifier-1 REPLACING CHARACTERS ALL identifier-2BY identifier-3 LEADING literal-1 literal-2... FIRST Format

 Literals must be single characters or figurative constants consistent with type of field being inspected  ALL, LEADING, CHARACTERS have same meaning as previously noted  FIRST means first occurrence of literal-1 will be replaced by literal-2  BEFORE/AFTER clause can be used

Inspect Date-In Replacing All '-' By '/' Inspect SSNo Replacing All Spaces By '-' FieldBeforeAfter Date-In /17/02 SSNo Examples

Inspect X1 Replacing Leading 'A' By 'Z' Inspect X2 Replacing First 'R' By 'Q' FieldBeforeAfter X1AAABBAZZZBBA X2RRSSTQRSST Examples

 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

 Code often stored in field to shorten record and minimize typing using the 88 numbered field  For example, 'H' or 'S' may represent pay type of 'Hourly' or 'Salaried'  Use condition names to check validity of coded fields

05 Pay-CodePic X. 88HourlyValue 'H'. 88SalariedValue 'S'. If Hourly Or Salaried Then Perform Pay-Calc-Rtn Else Perform Pay-Code-Err-Rtn End-If Example Data Division entries Procedure Division statements

 Class test - determine if field contains appropriate type of data (NUMERIC, ALPHABETIC)  Determine if data is missing by comparing field to SPACES  Replace spaces in numeric fields with ZEROS using INSPECT statement

 Range test - determine if field in established range  Limit test - determine if field exceeds established limit  Determine if field contains valid codes or values using condition-names to document and test fields  Can we use the inspect to solve our data entry problem of the lack of leading zeros and decimal spaces?

 Perform class tests first to ensure field is proper type  Use EVALUATE for further validation tests  Three common forms

EVALUATE identifier WHEN value(s) PERFORM … … Evaluate Pay-Code When 'H'Perform 300-Hourly-Rtn When 'S'Perform 400-Salaried-Rtn End-Evaluate Example

 May also use THRU clause to check range of values Evaluate Age When 0 Thru 19 Perform 400-Minor-Rtn When 20 Thru 99 Perform 500-Adult-Rtn End-Evaluate Example

EVALUATE TRUE WHEN condition PERFORM … … Evaluate True When Age >= 0 And <= 19 Perform 400-Minor-Rtn When Age >= 20 And <= 99 Perform 500-Adult-Rtn End-Evaluate Example

 Can also use with condition-names Assume these condition names defined for Age field 05 AgePic MinorValues 0 Thru AdultValues 20 Thru Example

Evaluate True When Minor Perform 400-Minor-Rtn When Adult Perform 500-Adult-Rtn End-Evaluate

 Note that using Age in place of True in this statement causes syntax error  Must compare numeric field Age to another numeric field or numeric literal  Compare TRUE to a condition or condition- name with value of TRUE or FALSE

EVALUATE condition WHEN TRUE PERFORM … WHEN FALSE PERFORM … Evaluate Age <= 19 When TruePerform 400-Minor-Rtn When FalsePerform 500-Adult-Rtn End-Evaluate Example

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

5.Use switch/If or 88 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

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

 Meaning of comma and decimal point in numbers in United States is reversed in some other nations  4, in United States represented as 4.123,45 in other nations  To change representation of numbers in COBOL use SPECIAL-NAMES paragraph

Environment Division. Configuration Section. Special-Names. Decimal-Point is Comma.  Number 4123,45 stored in field with PIC 9999V99  When moved to report-item with PIC 9.999,99 is displayed as 4.123,

 Restrictions on INSPECT statement limiting AFTER/BEFORE items to one-character literals or fields in REPLACING clause will be eleiminated  VALIDATE statement introduced to check format of data field ◦ Checks the format of data that is inputted from the user ◦ Could also solve are input problem

 Data Exception ◦ Performing operations on field containing blanks or other nonnumeric characters  Arithmetic operation  Comparison ◦ Failing to initialize subscript or index

 Divide Exception ◦ Attempting to divide by zero  Addressing Error ◦ Referring to array or table entry with value in subscript or index that exceeds number of entries in table ◦ Improperly coding nested PERFORMs or exiting from paragraph being performed

 Operation Error ◦ Attempting to access file with READ or WRITE before opening it or after closing it  Specification Error ◦ Attempting to access input area after AT END condition

 Illegal Character in Numeric Field ◦ May be caused by type mismatch between actual data and PIC clause ◦ Field size specified in PIC clause may not match actual size of field in record, leading to invalid (nonnumeric) characters from another field being treated as part of numeric field

 Two types of program errors ◦ Syntax errors ◦ Logic errors  Error control procedures can minimize errors but not eliminate them entirely  Page 456 – way to input data file name from users instead of always hard-coding it.  READ…INTO Statement page 456  INITIALIZE statement

 Types of error control procedures ◦ Range tests ◦ Limit tests ◦ Format tests ◦ Tests for missing data ◦ Sequence checks

 Other methods to validate data ◦ INSPECT statement ◦ Condition-names ◦ EVALUATE verb ◦ Verifying input data

 Handling input errors ◦ Stop the run ◦ Fill erroneous fields with spaces or zeros ◦ Stop the run if number of errors excessive ◦ Print control listings or audit trails to be checked