Скачать презентацию Chapter 4 Report Output and Validating Input Programming Скачать презентацию Chapter 4 Report Output and Validating Input Programming

e124218c25b4fdac373ee22d4fa4d227.ppt

  • Количество слайдов: 92

Chapter 4 Report Output and Validating Input Programming Logic for Business Copyright 2001 Laura Chapter 4 Report Output and Validating Input Programming Logic for Business Copyright 2001 Laura Saret Ed. D

Chapter Outline What Types of Reports Can Be Created? What Types of Lines Can Chapter Outline What Types of Reports Can Be Created? What Types of Lines Can Be Included on a Report? How Are Lines Spaced on a Page or Screen? Example: Heading Lines on Printed Reports, No Data Input From Outside the Program, and Using External Subroutines Example: Screen Output With Heading and Footing Lines How Do We Include the Date on a Report? Example: Exception Reports, Using an External Subroutine to Obtain the Current Date, Double Spacing Detail Lines, and Printing the Page Number in a Footing Line How Does “Garbage” Input Generate Output Errors? What Types of Data Validation Can Be Done?

Outline (continued) What Are the Differences Between Batch and On-line Data Entry and Validation? Outline (continued) What Are the Differences Between Batch and On-line Data Entry and Validation? Example: Input Validation for a Batch Program Example: Using an Interactive Program to Create and Validate an Input File What Is a Menu-driven Program? How Do Event Driven Programming Languages Enter and Validate Data?

Chapter Objectives After completing this chapter you should be able to. … Explain when Chapter Objectives After completing this chapter you should be able to. … Explain when it is appropriate to use detail, summary, exception, and query reports Describe the various types of lines that can be included on a report Explain how to space lines vertically on a page or screen Explain how to prevent scrolling on screen output Construct the logic for programs that produce paper and screen reports containing heading and/or footing lines Construct the logic for programs that have single- and doublespaced detail lines Construct the logic for programs that include the current date in a heading or footing line

Chapter Objectives (continued) After completing this chapter you should be able to. … Explain Chapter Objectives (continued) After completing this chapter you should be able to. … Explain and give examples of the types of errors that can occur during processing Explain how data-validation techniques prevent errors during processing and give examples of their appropriate uses Describe the difference between batch and on-line data entry and validation Construct the logic for programs that validate data already contained in a file Construct the logic for interactive programs that create and validate input files Describe how menu-driven programs are used to make programs user-friendly

What Types of Reports Can Be Created? Detail reports Summary reports Exception reports Query What Types of Reports Can Be Created? Detail reports Summary reports Exception reports Query reports

Detail Reports Name Test 1 Test 2 Average Grade Marilyn Smith Jonathan Kravitz Sena Detail Reports Name Test 1 Test 2 Average Grade Marilyn Smith Jonathan Kravitz Sena Kim Everett Schneider Betty Likowski 85 70 90 92 75 91 76 98 92 85 88 73 94 92 80 B C A A B Class Average 81. 4 89. 0 85. 2 Detail reports show information for every input record

Detail Reports Show information for every input record Each report line may contain all Detail Reports Show information for every input record Each report line may contain all or some fields from the input record Examples ¦ ¦ ¦ Customer list Phone directory Credit card statements showing all purchases and payments Class list Sales report that lists all sales by salesperson and region Report showing test scores for each student in a class

Summary Reports Grades earned for CIS 101 A’s B’s C’s D’s F’s 10 15 Summary Reports Grades earned for CIS 101 A’s B’s C’s D’s F’s 10 15 30 12 11 Summary reports do NOT show one line for each input record--the data is summarized

Summary Reports Data is summarized Examples ¦ ¦ ¦ A report of monthly and Summary Reports Data is summarized Examples ¦ ¦ ¦ A report of monthly and yearly sales totals for various products A report showing the total number of A’s, B’s, C’s, D’s and F’s given in a class A report listing the average amount charged last month by all customers

Exception Reports Name Test 1 Sena Kim Everett Schneider 90 92 Test 2 98 Exception Reports Name Test 1 Sena Kim Everett Schneider 90 92 Test 2 98 92 Exception reports shown information based on criteria specified within the program or by the user Average 94 92 Grade A A

Exception Reports Include some or all of the records from the input file The Exception Reports Include some or all of the records from the input file The records shown are determined by criteria within the program or specified by the user Examples ¦ ¦ ¦ A report showing items that need to be reordered A report listing students who are failing A report listing customers who did not pay their bills last month A list of salespersons who exceeded their yearly quotas An error report showing input records that contain invalid data

Query Reports Name Marilyn Smith Test 1 85 Test 2 Average 91 Query reports, Query Reports Name Marilyn Smith Test 1 85 Test 2 Average 91 Query reports, typically generated from asking questions about the records contained in a database, allow the user to obtain an immediate answer to a question 88 Grade B

Query Reports Generated from asking questions about the records contained in a database Allow Query Reports Generated from asking questions about the records contained in a database Allow the user to obtain an immediate answer to a question ¦ ¦ Was a customer’s check received? Did a student pay a parking fine? How many parts were ordered? Which WWW sites meet particular search criteria?

This Chapter Focuses on Detail and Exception Reports This Chapter Focuses on Detail and Exception Reports

What Types of Lines Can Be Included on a Report? Heading (header) and footing What Types of Lines Can Be Included on a Report? Heading (header) and footing (footer) lines Detail (data lines) Total (summary) lines

Heading (Footing) Lines Report heading/footing lines ¦ ¦ Appear once at the beginning (end) Heading (Footing) Lines Report heading/footing lines ¦ ¦ Appear once at the beginning (end) of the report-sometimes on a separate page or screen Contain information such as… ® name of the report ® date ® recipient of the report ® copyright information ¦ Report footing lines sometimes contain a line indicating the report has ended

Heading (Footing) Lines Page (screen) heading/footing lines ¦ ¦ Appear on each page Contain Heading (Footing) Lines Page (screen) heading/footing lines ¦ ¦ Appear on each page Contain information such as ® name of the report ® page number ® date ® instructions for the user to continue on the next screen Column heading lines ¦ Describe the fields that appear on the report Control heading lines ¦ Separate one group of data from another on the report

6/14/00 REPORT OF HOURS WORKED Employee Name TEAM 1 Smith, A. Garcia, J. TEAM 6/14/00 REPORT OF HOURS WORKED Employee Name TEAM 1 Smith, A. Garcia, J. TEAM 2 Date Hours Worked 6/10/00 6/12/00 6/14/00 8 12 6 --26 6/ 9/00 6/12/00 11 5 --16 Patel, P. 6/ 8/00 6/ 9/00 6/10/00 8 8 5 --21 Arnowitz, K. 6/13/00 6/14/00 Page heading line Column heading line Control heading line 3 4 --7 ABC LANDSCAPING COMPANY Page 1 Page footing line

Detail (Data) Lines Comprise the body of the report Hold information from the data Detail (Data) Lines Comprise the body of the report Hold information from the data contained on one or more input records

6/14/00 REPORT OF HOURS WORKED Employee Name TEAM 1 Hours Worked 6/10/00 6/12/00 6/14/00 6/14/00 REPORT OF HOURS WORKED Employee Name TEAM 1 Hours Worked 6/10/00 6/12/00 6/14/00 8 12 6 --26 Garcia, J. 6/ 9/00 6/12/00 11 5 --16 Patel, P. 6/ 8/00 6/ 9/00 6/10/00 8 8 5 --21 Arnowitz, K. TEAM 2 Smith, A. Date 6/13/00 6/14/00 3 4 --7 ABC LANDSCAPING COMPANY Page 1 Detail lines

Total (Summary) Lines Summarize information contained on a report Total (Summary) Lines Summarize information contained on a report

6/14/00 REPORT OF HOURS WORKED Employee Name TEAM 1 Date Hours Worked 6/10/00 6/12/00 6/14/00 REPORT OF HOURS WORKED Employee Name TEAM 1 Date Hours Worked 6/10/00 6/12/00 6/14/00 8 12 6 --26 Garcia, J. TEAM 2 Smith, A. 6/ 9/00 6/12/00 11 5 --16 Patel, P. 6/ 8/00 6/ 9/00 6/10/00 8 8 5 --21 Arnowitz, K. 6/13/00 6/14/00 3 4 --7 ABC LANDSCAPING COMPANY Page 1 Total lines

How Are Lines Spaced on a Page or Screen? Carriage control characters We tell How Are Lines Spaced on a Page or Screen? Carriage control characters We tell the computer to start a new page or screen by using instructions such as Write a line at top of page Single spaced lines ¦ Display a line at top of screen One line right after another with no blank lines between them Write a line Display a line Double spaced lines ¦ One blank line before each line with information Write a line double spaced Display a line double spaced Writing or displaying blank lines Write a blank line Display a blank line

How Does the Computer Know How Many Lines to Put on a Page? We How Does the Computer Know How Many Lines to Put on a Page? We use a lines counter

The Number of Lines That Can Fit on a Page (or Screen) Depends on The Number of Lines That Can Fit on a Page (or Screen) Depends on the… Size of the paper Font ¦ How the letters, numbers, and other characters you use look Font size ¦ How large each character is 10 point Times New Roman font 12 point Arial font 20 point Times New Roman font 28 point Times New Roman font

Scrolling When the computer runs out of room on the screen, it moves the Scrolling When the computer runs out of room on the screen, it moves the display up one line at a time. Information at the top of the screen is erased to make room for new information at the bottom

Printer and Display Layout Charts Columns and rows are numbered to show the spacing Printer and Display Layout Charts Columns and rows are numbered to show the spacing Two detail lines are shown to indicate that the detail lines are single spaced

Printer and Display Layout Charts Xs show nonnumeric fields 9 s show numeric fields Printer and Display Layout Charts Xs show nonnumeric fields 9 s show numeric fields Zs in a numeric field indicate zero suppression ¦ In length of call column 1156 displays as 1, 156 0009 displays as 9

Printer and Display Layout Charts Literals and constants such as heading lines, dollar signs, Printer and Display Layout Charts Literals and constants such as heading lines, dollar signs, and decimal points are included as they are to appear on the report Dates shown as MM/DD/YY indicate a 2 -digit month followed by a slash (/) followed by a 2 -digit day followed by a slash followed by a 2 -digit year

Let’s look at the Example in Section 4. 4 (page 137) No input file Let’s look at the Example in Section 4. 4 (page 137) No input file Report output ¦ ¦ Squares, Cubes, and square roots of the integers between 1 and 500 At most 25 detail lines per page

Look at the Data Dictionary (page 138) No input area defined All storage locations Look at the Data Dictionary (page 138) No input area defined All storage locations are defined as global Examine the Work Area ¦ ¦ 2 Heading lines are defined Integer-Counter, Square, Cube, Square-Root Lines-Counter Max-Lines

Look at the Mainline Routine It has a counter controlled loop What is the Look at the Mainline Routine It has a counter controlled loop What is the name of the variable used as the counter? What is the counter initialized to? Where is the counter initialized? Where is the counter incremented? By what value is the counter incremented?

Now, Look at Initialize How many times is Initialize done? What does it do? Now, Look at Initialize How many times is Initialize done? What does it do? Why is Lines-Counter initialized to 0? Why is Max-Lines initialized to 28?

Now, Examine Calculate Look at the instruction Square-Root = Sqrt(Integer. Counter) This instruction calls Now, Examine Calculate Look at the instruction Square-Root = Sqrt(Integer. Counter) This instruction calls an external subroutine ¦ ¦ ¦ A subroutine outside the program Not shown on the hierarchy chart How do you access it? ® Provide the name of the routine SQRT ® Provide field names or variables used in the subroutine Integer-Counter ® Provide a place (if any) to put the results Square-Root

What Does Calculate Do? Determines the square, cube, and square root Calls the Write-Detail What Does Calculate Do? Determines the square, cube, and square root Calls the Write-Detail routine to write a line on the report Adds 1 to Integer-Counter. Why?

Let’s Look at Write-Detail This routine writes detail lines on the report and controls Let’s Look at Write-Detail This routine writes detail lines on the report and controls the number of detail lines written on a page The first thing it does is determine whethere is room on the current page to write the next detail line ¦ When Lines-Counter is NOT less than Max-Lines, Headings are printed on the page BEFORE the detail line is written ¦ What is the value of Lines-Counter the first time Write-Detail is called? The detail line is written 1 is added to Lines-Counter

What Does Headings Do? Adds 1 to Page-Number Writes Heading 1 Writes Heading 2 What Does Headings Do? Adds 1 to Page-Number Writes Heading 1 Writes Heading 2 Writes a blank line Moves 3 to Lines-Counter ¦ Why?

Example 4. 5 (page 143) Screen output Footing lines on each page as well Example 4. 5 (page 143) Screen output Footing lines on each page as well as a report footer (REPORT COMPLETE)

Look at the Data Dictionary Some variables are local and some are global This Look at the Data Dictionary Some variables are local and some are global This is different from the previous example-both are correct ¦ ¦ Heading and footing lines are not given values in Initialize Headings uses them as constants rather than as storage locations that been previously been assigned values ® These values do not have to be ® Defined globally ® Passed to the Headings routine

What Does Mainline Do? Calls Initialize to… ¦ ¦ Assign global work areas Open What Does Mainline Do? Calls Initialize to… ¦ ¦ Assign global work areas Open files Do Headings for the first time ® This is different than the previous example ® Where were headings done for the first time in the previous example? ® Why is this example different? Read the first input record Calls Display-Detail for each input record Calls Terminate at EOF

Display-Detail is Called to Display Each Detail Line Checks Lines-Counter to make sure there Display-Detail is Called to Display Each Detail Line Checks Lines-Counter to make sure there is room to display the line on the screen If there is not enough room on the screen ¦ ¦ ¦ A message is displayed to the user indicating that a key should be pressed to continue The program waits for a response After getting the response, Headings is called If there is enough room on the screen or after doing Headings ¦ ¦ ¦ A line is displayed 1 is added to Lines-Counter The next record is read

What Does Headings Do? Clears the screen to remove whatever is currently displayed ¦ What Does Headings Do? Clears the screen to remove whatever is currently displayed ¦ Instead of clearing the screen, you can refresh the screen Displays Heading 1 at the top of the screen Displays Heading 2 on the next line Displays the blank line between the headings and first detail line ¦ Why is this done in Headings?

What Does Terminate Do? Displays the report footer ¦ ¦ Lines. Counter is not What Does Terminate Do? Displays the report footer ¦ ¦ Lines. Counter is not incremented Why? Closes files

Including the Current Date on a Report Obtain the date from the computer system Including the Current Date on a Report Obtain the date from the computer system using an external subroutine There are times when you don’t want to use the “system date”

The Example in Section 4. 7 Introduces. . . Exception reports Obtaining the current The Example in Section 4. 7 Introduces. . . Exception reports Obtaining the current date using an external subroutine Double spacing detail lines Using a footing line for the page number (page 149)

Why is This an Exception Report? Not all input records are included on the Why is This an Exception Report? Not all input records are included on the report The first instruction in the Process routine ¦ ¦ ¦ Compares Actual time to Scheduled time If the times are not the same, the record is included on the report If the times are the same, Process does not do Write. Detail--instead it just reads the next record

How is the Date Obtained From the System? The date is obtained in Initialize How is the Date Obtained From the System? The date is obtained in Initialize Why Initialize and not Headings? ¦ ¦ It is more efficient It prevents the date from changing in the middle of the report

How Does Having Double-Spaced Detail Lines Affect the Logic? Lines-Counter needs to be incremented How Does Having Double-Spaced Detail Lines Affect the Logic? Lines-Counter needs to be incremented by 2 ¦ ¦ One for the line One for the blank line that precedes it The blank line between the headings and the first detail line is written in the Write-Detail routine ¦ ¦ The previous example wrote this blank line as part of Headings Why is this different?

Printing Footings on Each Page In Write-Detail… ¦ Footings is called prior to doing Printing Footings on Each Page In Write-Detail… ¦ Footings is called prior to doing Headings In Initialize… ¦ ¦ Headings are called In this way we don’t do footings on the first page BEFORE writing the first detail line Footings on last page of report ¦ Terminate has to write blank lines until Lines-Counter equals Max-Lines ® Why? ¦ If there are no input records--the input file is empty--the page with the error message will have a footing line. ® Can this be avoided?

If there are no input records--the input file is empty--the page with the error If there are no input records--the input file is empty--the page with the error message will have a footing line. Can this be avoided? Assign a storage location for Error-Indicator Give Error-Indicator an initial value of “NO” After writing the error message in Mainline, move “YES” to Error-Indicator Check Error-Indicator at the start of Terminate. ¦ If Error-Indicator is “YES”, do not print the footings

ge an ch om t’s s fr e u ut L c tp r ge an ch om t’s s fr e u ut L c tp r o rt ou de f o si ep con t r nd inpu a

Errors During Program Translation and Execution Translation (syntax errors) prevent the program from being Errors During Program Translation and Execution Translation (syntax errors) prevent the program from being executed ¦ ¦ Using a variable name that starts with a number instead of a letter Branching to an instruction or calling a subroutine that does not exist Misspelling an instruction (PRNT) Using a variable name that has not been defined in languages that require the definition Execution (logic) errors occur after the translation process while the program is being executed

Execution (Logic) Errors in logic that cause incorrect output ¦ ¦ Using an Add Execution (Logic) Errors in logic that cause incorrect output ¦ ¦ Using an Add rather than a Subtract instruction Processing data in an incorrect sequence Errors in logic that cause a program interrupt ¦ ¦ Attempting to do an arithmetic on a field that does not contain a number (data-exception error) Accessing a nonexistent entry in an array or table CAREFUL TESTING SHOULD ELIMINATE ALL LOGIC ERRORS!!!!!

Garbage In--Garbage Out (GIGO) Garbage In--Garbage Out (GIGO)

Datavalidation techniques check for input errors prior to processing Datavalidation techniques check for input errors prior to processing

What Types of Data Validation Can Be Done? Data type Range of values Exact What Types of Data Validation Can Be Done? Data type Range of values Exact value or values Sign Data presence Data consistency Data reasonableness Data sequence Check digit calculations Table or file lookup Visual verification

Data Type Ensures that storage areas contain the correct type (e. g. , numeric) Data Type Ensures that storage areas contain the correct type (e. g. , numeric) of data IF AMOUNT is not numeric THEN MOVE “AMOUNT IS NOT NUMERIC” to ERROR-MESSAGE DO WRITE-ERROR routine ENDIF What will happen if AMOUNT should have been 2. 34 and the user enters 2. 76? We can make sure a numeric value was entered, but we cannot guarantee that the CORRECT number was entered. Therefore, even if a validation program indicates that there were no errors, it doesn’t mean that there are no errors--it means that those errors checked for were not found!

Range of values Suppose a test score should be in the range 0 -100 Range of values Suppose a test score should be in the range 0 -100 IF SCORE < 0 Then MOVE “SCORE IS INVALID” to ERROR-MESSAGE DO WRITE-ERROR routine ELSE IF SCORE > 100 THEN MOVE “SCORE IS INVALID” to ERROR-MESSAGE DO WRITE-ERROR routine ENDIF IF SCORE is not 0 -100 THEN MOVE “SCORE IS INVALID” to ERROR-MESSAGE DO WRITE-ERROR routine ENDIF IF SCORE is < 0 or SCORE is > 100 THEN MOVE “SCORE IS INVALID” to ERROR-MESSAGE DO WRITE-ERROR routine ENDIF We can confirm that the range is 0 to 100, but we can’t guarantee that the correct number has been entered!

Exact Value or Values Suppose commissions are calculated based on a code of 1, Exact Value or Values Suppose commissions are calculated based on a code of 1, 2, or 3 Code = ? 1 Do Code 1 2 3 Other Do Code 2 Do Code 3 Move "Code is invalid" to Error-Message Do Write-Error We can confirm that the code is 1, 2, or 3 but we can’t guarantee that the correct code has been entered!

Exact Value or Values Sometimes codes or fields are entered as letters rather than Exact Value or Values Sometimes codes or fields are entered as letters rather than numbers. We must check for both upper and lowercase. IF GENDER is equal to “m” THEN MOVE “M” to GENDER ELSE IF GENDER is equal to “f” THEN MOVE “F” to GENDER ELSE IF GENDER is not equal to “M” THEN IF GENDER is not equal to “F” THEN MOVE “GENDER IS INVALID” to ERROR-MESSAGE DO WRITE-ERROR routine ENDIF We can confirm that the value ENDIF entered is M, m, F, or f-- we can’t ENDIF guarantee that the correct value has been entered!

Sign Ensures that a numeric value is either positive, zero, or negative The following Sign Ensures that a numeric value is either positive, zero, or negative The following example validates that a purchase amount is greater than 0 IF AMOUNT is less than or equal to zero THEN MOVE “AMOUNT IS INVALID” to ERROR-MESSAGE DO WRITE-ERROR routine ENDIF We can confirm that the value entered is greater than 0 -- we can’t guarantee that the correct value has been entered!

Data Presence Ensures that an input field contains a value other than spaces or Data Presence Ensures that an input field contains a value other than spaces or blanks. The following example ensures that a name is not blank. Is Name blank? Yes Move "Name is blank" to Error-Message No Do Write-Error We can confirm that the name is not blank-- we can’t guarantee that the correct name has been entered!

Data Consistency Checks the consistency of one data value against another ¦ If the Data Consistency Checks the consistency of one data value against another ¦ If the student’s gender is F, make sure that she does not register for boy’s choir Is Gender = "F"? No Yes Is Move “Inconsistent Course = Data" to "Boys' Choir" Yes Error-Message ? No Do Write-Error We can confirm that the data are consistent-we can’t guarantee that they are correct

Data Reasonableness All techniques ensure that input data are reasonable Some checking does not Data Reasonableness All techniques ensure that input data are reasonable Some checking does not fit in any other category ¦ ¦ 5 -digit part number is really 5 digits The year a payment was made is not greater than the current year Is Move "Year is Year-Input > Invalid" to Current-Year Yes Error-Message No Do Write-Error We can confirm that the year is not greater than the current year-- we can’t guarantee that the correct value has been entered!

Data Sequence Makes sure data are input in a certain order No values are Data Sequence Makes sure data are input in a certain order No values are missing Is Number > Previous. Number Yes No Move Number to Previous-Number Move “Number is Out of sequence” to Error-Message Previous-Number is a work area containing the previous number input--if the number was valid. Previous-Number is initialized to a value less than the first Number input. Do Write-Error We can confirm that the input are in order-- we can’t guarantee that the correct values have been entered!!!

Sequence Checking--Making Sure No Records are Missing Looking for “missing” checks LOOP WHILE PREVIOUS-NUMBER Sequence Checking--Making Sure No Records are Missing Looking for “missing” checks LOOP WHILE PREVIOUS-NUMBER is less than NUMBER MOVE PREVIOUS-NUMBER to ERROR-MESSAGE DO WRITE-ERROR routine ADD 1 to PREVIOUS-NUMBER ENDLOOP

Reports Showing Out of Sequence Records May NOT be Accurate! Input: 1 ¦ ¦ Reports Showing Out of Sequence Records May NOT be Accurate! Input: 1 ¦ ¦ ¦ 3 4 8 6 9 10 6 is shown as out of sequence Input: 1 ¦ 2 2 3 99 4 5 6 8 9 10 4, 5, 6, 8, 9, 10 are shown as out of sequence What is really out of sequence? Why does this happen?

Check Digit Calculations Helps avoid data transposition errors ¦ E. g. , entering 1256 Check Digit Calculations Helps avoid data transposition errors ¦ E. g. , entering 1256 instead of 1265 There are many methods for generating check digits

Here is One Example for Generating a Check-Digit Suppose the original number is 84913 Here is One Example for Generating a Check-Digit Suppose the original number is 84913 1. 2. 3. 4. 5. Multiply alternate digits by 2 8 * 2 = 16 9 * 2 = 18 3*2=6 Add the digits that result from the multiplications (Note: 16 becomes the digits 1 and 6; 18 becomes the digits 1 and 8) 1 + 6 + 1 + 8 + 6 = 22 Add the digits from the original number not included in step 1 to the result in step 2 4 + 1 + 22 = 27 Use the 1 s place of the result of step 3 (the value 7) as the check digit The check digit becomes the last digit of the customer number 849137 When the program validates the customer number, the computer uses the first 5 digits of the customer number and recomputes the check digit. If it is the same as the check digit, then no error has occurred.

Table or File Lookup Look up a value in a table (array) or file Table or File Lookup Look up a value in a table (array) or file to see if it is there We can confirm that the value is in the table-we can’t guarantee that the correct value has been entered! Table of Part Numbers 129870954 102872343 109879099 182710809 198776619 238765172 102874650

Visual Verification Are you sure this is correct? Press enter to continue Josep h Visual Verification Are you sure this is correct? Press enter to continue Josep h Are y ou sure?

Validation Can be Done in Batch or Online Mode Batch ¦ ¦ ¦ Groups Validation Can be Done in Batch or Online Mode Batch ¦ ¦ ¦ Groups (batches) of data are collected Data are processed at specific time intervals (daily, weekly, monthly) Examples: ® Billing ® Payroll ® Grades Online ¦ ¦ Data are processed when they occur Examples ® Ticket reservations ® Inventory systems ® Banking

Batch Mode Validation program checks the input data Sometimes validation is part of the Batch Mode Validation program checks the input data Sometimes validation is part of the data entry process Sometimes validation is a separate program Output from a validation program… ¦ List of errors ¦ File containing valid records When errors occur we either… ¦ Process valid records and wait to process invalid records the next time a batch is processed ¦ Correct records and then process the entire batch Don’t stop looking for errors when you find the first error on a record!!!!

Online Mode Interactive programs Menu-driven programs Input forms Online Mode Interactive programs Menu-driven programs Input forms

Example in Section 4. 11 (page 163)-Input Validation for a Batch Program Validate input Example in Section 4. 11 (page 163)-Input Validation for a Batch Program Validate input for an accounts receivable system Output is… Error report ¦ File containing the valid records Notice that two output areas are defined Two indicators are used ¦ File-Error ¦ Record-Error ¦

File-Error Tracks whether any error messages are written on the report The Terminate routine File-Error Tracks whether any error messages are written on the report The Terminate routine checks File-Error… If File-Error = “NO” then “No Errors Found—All Records Correct” is written on the report ¦ If File-Error = “YES” then the message is not written File-Error is initialized to “NO” in Initialize How does File-Error become “YES”? ¦ If an error occurs, Process calls Write-Error ¦ Write-Error calls Headings ¦ Headings moves “YES” to File-Error It is more efficient to move “YES” to File-Error in the Headings routine than in the Write-Error routine. Why? Once “YES” is moved to File-Error, it is not reset to “NO” ¦

Record-Error Tracks whether any errors occur when checking the current input record Record-Error is Record-Error Tracks whether any errors occur when checking the current input record Record-Error is used for two purposes ¦ ¦ If the record currently being processed contains no errors, then the record must be written to the output file For every record input, the content of the record is listed only once on the error report regardless of how many errors the record contains Record-Error is set to “NO” whenever a record is read Record-Error is given a value of “YES” whenever an error occurs (Write-Error)

Uses of Record-Error If the record currently being processed contains no errors, then the Uses of Record-Error If the record currently being processed contains no errors, then the record must be written to the output file ¦ At the end of Process (before reading the next record), Record-Error is checked ® If its value is “NO”, the record is written to the file ® If its value is “YES”, the record is not written to the file IF RECORD-ERROR = “NO” THEN WRITE a record (ACCT-NUM, NAME, PRODUCT, QUANITY) to ACCOUNTOUT file ENDIF

Uses of Record-Error For every record input, the content of the record is listed Uses of Record-Error For every record input, the content of the record is listed only once on the error report regardless of how many errors the record contains ¦ Write-Error checks Record-Error ® If its value is “NO”, the input record is written on the report ® If its value is “YES”, then blanks (spaces) are shown on the report instead of the record IF RECORD-ERROR = “YES” THEN MOVE spaces to BAD-RECORD ELSE MOVE ACCT-NUM, NAME, PRODUCT, QUANITY to BAD-RECORD MOVE “YES” to RECORD-ERROR ENDIF

Process Does the Validation Notice the following ¦ ¦ If Acct-Num is not numeric, Process Does the Validation Notice the following ¦ ¦ If Acct-Num is not numeric, no sequence checking occurs If Quantity is not numeric, we don’t check to see if its value is greater than 0

Example in Section 4. 12 (page 170)— Using an Interactive Program to Create and Example in Section 4. 12 (page 170)— Using an Interactive Program to Create and Validate an Input File Validate input as they are entered No error report is required ¦ ¦ Error messages are displayed on the screen, and invalid data are corrected immediately File containing the valid records is created This example creates an inventory file containing part numbers and the number of items added to or removed from inventory The Interactive Procedure on page 172 shows the… ¦ ¦ ¦ Lines displayed Possible responses Programming paths followed based on the responses

Let’s look at the Data Dictionary RESPONSE holds the responses entered by the user Let’s look at the Data Dictionary RESPONSE holds the responses entered by the user Part number ¦ Number of items ¦ Addition to or removal from inventory 2 output areas ¦ DISPLAY-LINE ¦ INVENTORY-FILE The actual lines to be displayed are described in the work area and used as local constants by the program Other work areas ¦ Validated input ® PART ® NUMBER ® A-OR-R ¦ 2 indicators ® DONE ® VALID-RESPONSE ¦

Done Tracks whether processing is complete The Mainline routine checks Done to determine whether Done Tracks whether processing is complete The Mainline routine checks Done to determine whether to do the Process routine Its initial value is “NO” in Initialize What changes Done’s value to “YES”?

Valid-Response Each routine requesting user input contain a loop to request and validate the Valid-Response Each routine requesting user input contain a loop to request and validate the user’s response Valid-Response tracks whether the response entered by the user is valid If the response is valid… ¦ ¦ “YES” is moved to Valid-Response The program exits the loop If the response is invalid… ¦ ¦ “NO” is moved to Valid-Response The program continues in the loop

Look at the Process Routine (page 174) Notice that each of the loops is Look at the Process Routine (page 174) Notice that each of the loops is very similar ¦ The first loop does Display-Line 2 until a valid response is obtained for Part ® If the response is 0, then the program moves “YES” to Done The second loop does Display-Line 3 until a valid response is obtained for Number ¦ The third loop does Display-Line 4 until a valid response is obtained for A-or-R After obtaining the values, Write-Record is called ¦ It uses visual verification to determine whether the record should be written on the file ¦

What Is a Menu-Driven Program? Menus allow the user to make choices about what What Is a Menu-Driven Program? Menus allow the user to make choices about what the program should do Menu-driven programs are user-friendly STUDENT REPORT OPTIONS Enter the number corresponding to your choice: 1 Report for all students 2 Report for all students by department 3 Report for all students by teacher 4 Report for an individual student 5 Exit program

Main Menus and Submenus STUDENT REPORT OPTIONS Enter the number corresponding to your choice: Main Menus and Submenus STUDENT REPORT OPTIONS Enter the number corresponding to your choice: 1 Report for all students 2 Report for all students by department 3 Report for all students by teacher 4 Report for an individual student 5 Exit program SELECT TEACHER Abbas Bloom Carter Edwards Liu

How Do Event-Driven Programming Languages Enter and Validate Data? An entire screen (form) is How Do Event-Driven Programming Languages Enter and Validate Data? An entire screen (form) is displayed, and the values can be entered by the user in any order desired

This Is the Next Form Shown This Is the Next Form Shown

Sample List Box When the user selects an item, it is highlighted. Scroll bars Sample List Box When the user selects an item, it is highlighted. Scroll bars are provided to allow the user to easily select other items in the list.

Sample Message Box The user selects one of the buttons shown Sample Message Box The user selects one of the buttons shown