ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INPUT-DATA
ASSIGN TO 'A:\METER.TXT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT REPORT-FILE
ASSIGN TO 'A:\REPORT.TXT'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD INPUT-DATA
DATA RECORD IS INPUT-RECORD.
01 INPUT-RECORD.
02 INPUT-CUST-ID-NUMBER PIC X(5).
02 INPUT-CUST-NAME PIC X(25).
02 INPUT-KILOWATT-HOURS PIC 9(4).
FD REPORT-FILE
DATA RECORD IS REPORT-LINE.
01 REPORT-LINE PIC X(80).
WORKING-STORAGE SECTION.
01 NO-MORE-DATA-SWITCH PIC X VALUE SPACE.
01 ENERGY-RATE PIC V9(2) VALUE .08.
01 WS-ENERGY-CHARGE PIC 9(4)V99.
01 TOTAL-NUMBER-OF-RECORDS PIC 9(4) VALUE ZERO.
01 TOTAL-KILOWATT-HOURS PIC 9(8) VALUE ZERO.
01 TOTAL-ENERGY-CHARGE PIC 9(8)V99 VALUE ZERO.
01 HEADER-LINE.
02 FILLER PIC X(10) VALUE 'CUST#'.
02 FILLER PIC X(28) VALUE
'CUSTOMER NAME'.
02 FILLER PIC X(6) VALUE
'KW HRS'.
02 FILLER PIC X(3) VALUE SPACES.
02 FILLER PIC X(10) VALUE
'AMT BILLED'.
01 DETAIL-LINE.
02 DETAIL-CUST-ID-NUMBER PIC X(5).
02 FILLER PIC X(5) VALUE SPACES.
02 DETAIL-CUST-NAME PIC X(25).
02 FILLER PIC X(5) VALUE SPACES.
02 DETAIL-KILOWATT-HOURS PIC ZZZ9.
02 FILLER PIC X(5) VALUE SPACES.
02 DETAIL-ENERGY-CHARGE PIC Z,ZZ9.99.
01 TOTAL-LINE.
02 FILLER PIC X(10) VALUE 'TOTALS->'.
02 FILLER PIC X(11) VALUE
'CUSTOMERS: '.
02 TL-NUMBER-OF-RECORDS PIC ZZZ9.
02 FILLER PIC X(13) VALUE
' KW HOURS: '.
02 TL-KILOWATT-HOURS PIC ZZ,ZZZ,ZZ9.
02 FILLER PIC X(18) VALUE
' AMOUNT BILLED: '.
02 TL-ENERGY-CHARGE PIC ZZ,ZZZ,ZZ9.99.
PROCEDURE DIVISION.
MAIN-PARAGRAPH.
PERFORM STARTUP-PARAGRAPH.
PERFORM PRINT-HEADER.
PERFORM PROCESS-RECORDS
UNTIL NO-MORE-DATA-SWITCH = 'Y'.
PERFORM TOTAL-ROUTINE.
PERFORM CLEANUP-PARAGRAPH.
STOP RUN.
STARTUP-PARAGRAPH.
OPEN INPUT INPUT-DATA.
OPEN OUTPUT REPORT-FILE.
READ INPUT-DATA
AT END MOVE 'Y' TO NO-MORE-DATA-SWITCH.
PROCESS-RECORDS.
MOVE INPUT-CUST-ID-NUMBER TO DETAIL-CUST-ID-NUMBER.
MOVE INPUT-CUST-NAME TO DETAIL-CUST-NAME.
MOVE INPUT-KILOWATT-HOURS TO DETAIL-KILOWATT-HOURS.
COMPUTE WS-ENERGY-CHARGE ROUNDED =
ENERGY-RATE * INPUT-KILOWATT-HOURS.
MOVE WS-ENERGY-CHARGE TO DETAIL-ENERGY-CHARGE.
MOVE DETAIL-LINE TO REPORT-LINE.
WRITE REPORT-LINE.
ADD 1 TO TOTAL-NUMBER-OF-RECORDS.
ADD WS-ENERGY-CHARGE TO TOTAL-ENERGY-CHARGE.
ADD INPUT-KILOWATT-HOURS TO TOTAL-KILOWATT-HOURS.
READ INPUT-DATA
AT END MOVE 'Y' TO NO-MORE-DATA-SWITCH.
PRINT-HEADER.
MOVE HEADER-LINE TO REPORT-LINE.
WRITE REPORT-LINE AFTER ADVANCING PAGE.
MOVE SPACES TO REPORT-LINE.
WRITE REPORT-LINE.
TOTAL-ROUTINE.
MOVE TOTAL-NUMBER-OF-RECORDS TO TL-NUMBER-OF-RECORDS.
MOVE TOTAL-KILOWATT-HOURS TO TL-KILOWATT-HOURS.
MOVE TOTAL-ENERGY-CHARGE TO TL-ENERGY-CHARGE.
MOVE TOTAL-LINE TO REPORT-LINE.
WRITE REPORT-LINE AFTER 2.
CLEANUP-PARAGRAPH.
CLOSE INPUT-DATA.
CLOSE REPORT-FILE.