Program 4 is responsible for printing a report of customer records from the updated customer master file (TB17NF.DAT) generated by Program 3. The report also indicates customers who's balance exceeds their allotted credit limit (and print the excess amount alongside). A running total of customer balances is indicated on each page, i.e. "Balance carried forward" at the bottom of each page and "Balance brought forward" at the top of the following page. The footer for this report shows the grand total of customer balances, the total number of records in the new file, and how many are debtors. 4.1 Solution The control paragraph, CONTROL-PARAGRAPH, starts by executing the print and read initiation procedure INITIAL-PROCESS. As with previous programs, this paragraph opens new customer master file (IN-FILE) and printer, sets the system date, prints the titles and column headers, sets the page number to 1, and performs the prime read of the IN-FILE. The PRINT-HEADERS paragraph differs from earlier programs in that the balance brought forward is printed at the top of the new page. This occurs when the page number is greater than 1 to avoid printing the balance on the title page. The total balance (calculated as each record is read) is used to set the balance brought forward print item. The main iteration is performed on the paragraph MAIN-PROCESS until the IN-FILE is read to completion. The record being processed is first tested to determine whether the customer's balance is greater than the customer's credit limit. When this is true, the debtor warning print item is set to ">>>", otherwise it is set to spaces. The customer's balance is added to the total balance and then the PRINT-CUSTOMER-RECORD paragraph is performed. The ON SIZE ERROR within the ADD statement acts only to display an on-screen warning to the operator if the balance exceeds the picture size definition.
Printing customer records Each of the print fields are set to the appropriate record field. Using the same method as described in Program 2, the address is split into address lines for readability using the UNSTRING statement. The first address line is moved to the main print line which is then printed. Additional address lines are then printed. If the record is marked as a debtor (when P-DEBT-WARNING = ">>>") then the credit limit is subtracted from the customer's balance to give the amount outstanding, which is then printed after the address. For each additional print line, the line number is appropriately increased. When the logic returns to the MAIN-PROCESS the line number is tested. When it exceeds 40 lines then the balance carried forward (set to the total balance) is printed and a new page started before the PRINT-HEADERS paragraph is executed.
Program termination When the file is completely read the MAIN-PROCESS loop is exited and CONTROL-PARAGRAPH then executes the termination paragraph TERMINATION-PROCESS. Here the report footers are printed, indicating total records read, total number of debtors and the grand total of all customer balances. The end of report message is printed and the IN-FILE and printer are closed. Logic then returns to the control paragraph where the program is stopped.
|