Presentation is loading. Please wait.

Presentation is loading. Please wait.

General Algorithms for Common Business Problems Simple Program Design Third Edition A Step-by-Step Approach 10.

Similar presentations


Presentation on theme: "General Algorithms for Common Business Problems Simple Program Design Third Edition A Step-by-Step Approach 10."— Presentation transcript:

1

2 General Algorithms for Common Business Problems Simple Program Design Third Edition A Step-by-Step Approach 10

3 Objectives To provide general pseudocode algorithms to four common business applications. Topics covered are: –report generation with page break –single-level control break –multiple-level control break –sequential file update 10

4 Program Structure The aim of this chapter is to present a number of general pseudocode solutions to a selection of typical programming problems Reference has been made to a general solution algorithm for the processing of sequential files This algorithm is a skeleton solution, and in pseudocode looks like the example shown on page 150 of the textbook This basic solution algorithm forms the framework for almost all commercial business programs 10

5 Program Structure This general solution algorithm can also be modularized as shown on page 150 of the textbook The mainline module would now look like the code listed at the bottom of page 150 of the textbook 10

6 Most reports require page heading lines, column heading lines, detail lines, and total lines A typical report might look similar to the example shown on page 151 of the textbook A) Hierarchy chart Once the hierarchy chart has been established, the solution algorithm can be developed in pseudocode Refer to the hierarchy chart shown on page 151 of the textbook B) Solution algorithm (refer to the pseudocode displayed on page 152 of the textbook) 10 Report Generation with Page Break

7 Single-Level Control Break Printed reports that also produce control break total lines are very common in business applications A control break total line is a summary line for a group of records that contain the same record key Reports that print control break totals can be categorized as being either single-level or multiple-level control break reports, depending on whether there is one control field or more than one control field 10

8 Single-Level Control Break There are two things you must consider when designing a control break program: 1.The file to be processed must have been sorted into control field sequence 2.Each time a record is read from the input file, the control field on the current record must be compared with the control field on the previous record A) Hierarchy chart (refer to the chart shown on page 154 of the textbook for an example) B) Solution algorithm (see the pseudocode for the mainline on page 154 of the textbook) 10

9 Single-Level Control Break There are four points in this mainline algorithm that are essential for a control break program to function correctly: 1.Each time a new record is read from the file, the new control field is assigned to the variable this_control_field 2.When the first record is read, the new control field is assigned to both the variables this_control_field and prev_control_field 3.The variables prev_control_field is updated as soon as a change in the control field is detected 4.After the end of the file has been detected, the module Print_control_total_line is called Subordinates modules are shown on page 155 and 156 of the textbook for your reference 10

10 Multiple-Level Control Break Often reports are required to produce multiple- level control break totals The Monthly Sales Report might then look like the example shown on page 156 of the textbook The concepts that applied to a single-level control break program also apply to a multiple-level control break program: 1.The input file must be sorted into control field sequence 2.Each time a record is read from the file, the control field on the current record must be compared with the control field of the previous record 10

11 Multiple-Level Control Break The general solution algorithm which was developed for a single-level control break program can be extended by the addition of two new modules to incorporate a two-level control break A) Hierarchy chart (see the diagram shown on page 157 of the textbook for an example) B) Solution algorithm (refer to the Mainline example shown on page 157 of the textbook and the Subordinate modules on page 159 and 160) 10

12 Multiple-Level Control Break The points to be noted in this mainline are: 1.Each time a new record is read from the input file, the new control fields are assigned to the variables this_minor_control_field and this_major_control_field 2.When the first record is read, the new control fields are assigned to both the current and previous control field variables 3.After the end of the input file has been detected, the two modules Print_minor_control_totals and Print_major_control_totals will be called Because the solution algorithm has simple design and good modular structure, the processing of intermediate control field breaks as well as major and minor control field breaks can be handled easily 10

13 Sequential File Update Sequential file updating is a very common batch processing application It involves updating a master file by the application of update transactions on a transaction file Both files are sequential A system flow chart of a sequential update program is shown on page 161 of the textbook 10

14 System Concepts 1Master File A master file is a file that contains permanent and semi-permanent information about the data entities it contains 2Transaction File A transaction file contains all the data and activities that are included on the master file 10

15 System Concepts 3Audit Report An audit report is a detailed list of all the transactions that were applied to the master file 4Error Report An error report is a detailed list of errors that occurred during the processing of the update 10

16 Sequential Update Logic The logic of a sequential update program is more difficult than the other problems encountered, because there are two sequential input files Processing involves reading a record from each of the input files and comparing the keys of the two records Processing falls generally into three categories: 1.If the transaction record key is less than the old master record key, the transaction is probably an add transaction 2.If the transaction record key is equal to the old master record key, the transaction is probably an update or delete transaction 3.If the transaction record key is greater than the old master record key, there is no matching transaction for that master record 10

17 Sequential Update Logic Sequential update programs also need to include logic that will handle multiple transaction records for the same master record, and the possibility of transaction records that are in error The types of transaction record errors that can occur are: 1.An attempt to add a new master record when a record with that key already exists on the master file 2.An attempt to update a master record when there is no record with that key on the master file 3.An attempt to delete a master record when there is no record with that key on the master file 4.An attempt to delete a master record when the current balance is not equal to zero 10

18 Balance Line Algorithm A good general solution algorithm is written in pseudocode by Barry Dwyer, in a paper entitled ‘One More Time — How to Update a Master File’ This algorithm has been referred to as the balance line algorithm It handles multiple transaction records for the one master record as well as the possibility of transaction record errors A) Hierarchy chart (see the diagram at the top of page 164 of the textbook) B) Solution algorithm (refer to the pseudocode on pages 164 to 166 of the textbook) 10

19 Summary The aim of this chapter was to develop general pseudocode algorithms to four common business applications The applications covered were: –report generation with page break –single-level control break –multiple-level control break –sequential file update In each section, the application was discussed, a hierarchy chart was developed, and a general solution algorithm was presented in pseudocode 10


Download ppt "General Algorithms for Common Business Problems Simple Program Design Third Edition A Step-by-Step Approach 10."

Similar presentations


Ads by Google