|
2. Program 2
Program 2 is responsible for two processes. Firstly, to sort the valid transaction file (TB17VF.DAT generated by Program 1) into ascending order of customer code. Where more than one transaction appears for a single customer, then record is sorted on descending record type, i.e. R > I > D > C type records. The sorted records are written to a new sorted transaction file (TB17SD.DAT). It is important that the records are sorted in the manner described above in order to comply with the processing of transactions that occur during Program 3 execution. The second action of Program 2 is to print a report of all the records in the sorted file along with total of all records and a tally of each record type. 2.1 Solution The main control paragraph of Program 2 (MAIN-PARAGRAPH) begins by performing the sort function of this program by calling SORT-PARAGRAPH. Here the valid transaction file (TB17VF.DAT) produced by Program 1 is opened and sorted into a new file (TB17SD.DAT) referred to as the Sorted file. This involves a temporary work file. For compilation using the MicroFocus compiler, the work file is assigned to 'WORK-FILE.DAT' in the environment division, whereas compilation by the Fujitsu COBOL85 compiler, the work-file is assigned to SORTWK01. The sort process sorts records on an ascending customer code primary key, and on a descending record type secondary key. This is to ensure that where multiple transactions occur for a single customer the record type appears in the correct order that is acceptable for processing by Program 3 (see Program 3 Solution). The sort utility automatically closes files once completed. Following the sort process, the second function of Program 2 is to print the Sorted file on a report that is initiated in INITATE-PRINT. Here files are opened, the system date is acquired and the titles, page number and column headers (via PRINT-HEADERS) is printed on a new page. This is followed by the prime read of the Sorted file. The main iteration of the program is performed on PRINT-RECORD-LINE until the end of the Sorted file is reached. Using a similar process as described for Program 1, the record being processed is tested for record type using an EVALUATE statement, directing the logic to record type-specific paragraphs in order to set up appropriate print fields as well as to make a tally of each record type. The main differences between Program 1 and Program 2 printing are (i) no error codes are being reported, and (ii) the address in creation records is printed in a more readable format. Paragraph C-REC-PRINT sets up print items for record type, customer code, name, balance and credit limit. The address is divided into separate lines by the ";" delimiter using the UNSTRING statement. The first address line is moved into the address line print item of the main print line. Subsequent address lines are moved into a table in elements 2, 3 and 4. The first element is not used simply for reasons for clarity. The TALLY IN [ADDRESS-LINE-NO] clause of the UNSTRING statement is used to note the number of elements actually filled with address lines. This allows for addresses that have less than four lines in total, thereby avoiding printing blank lines for unfilled print table elements. The item ADDRESS-LINE-NO is then used to control the subscript number when printing the additional address lines when the logic returns to PRINT-RECORD-LINE, i.e. PERFORM VARYING SUBS-NO [subscript item] FROM 2 BY 1 UNTIL SUBS-NO > ADDRESS-LINE-NO (lines 002840 and 002850). Within this PERFORM loop, the line number is also adjusted to maintain the correct line number. The line number is tested to ensure that it does not exceed 50 lines (otherwise a new page is started), followed by reading the Sorted file for the next record. When all records have been read then final paragraph, TERMINATION-PARAGRAPH, is executed. Here the total record count and individual record type totals are printed as footers, along with a key to record type abbreviations and an end of report message. Lastly, files are closed and the program stopped.
Program limitations As discussed above (Program 1 limitations), Program 2 is not able to detect duplications of deletion or creation type records. Removal of such duplications could be achieved by initially placing sorted records into a temporary file and then re-reading these records into the sorted file while testing for (and removing) duplications. |