I'm working in COBOL with a double control break to print a hospital record. The input is one record per line, with, hospital info first, then patient info. There are multiple records per hospital, and multiple services per patient.
The idea is, using a double control break, to print one hospital name, then all the patients from that hospital. Then print the patient name just once for all services, like the below.
I'm having trouble with my output, and am hoping someone can help me get it in order.
I am using AccuCobol to compile
experts-exchange does not allow .cob and .dat so the extentions were changed to .txt
The files are: the .cob lab5b.cob
the input / output: lab5bin.dat, lab5bout.dat
The assignment: http://www.cse.ohio-state.edu/~sgomori/314/lab5.html
Hospital Number: 001
Hospital Name: Mount Carmel
00001 Griese, Brian Ear Infection 08/24/1999 300.00
Diaper Rash 09/05/1999 25.00
Frontal Labotomy 09/25/1999 25,000.00
Rear Labotomy 09/26/1999 25,000.00
Central Labotomy 09/28/1999 24,999.99
The total amount owed for this patient is: $..........
(End of Hospital)
The total amount owed for this hospital is: $.........
enter code here
IDENTIFICATION DIVISION.
PROGRAM-ID. LAB5B.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT FILE-IN ASSIGN TO 'lab5bin.dat'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT FILE-OUT ASSIGN TO 'lab5bout.dat'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD FILE-IN.
01 HOSPITAL-RECORD-IN.
05 HOSPITAL-NUMBER-IN PIC 999.
05 HOSPITAL-NAME-IN PIC X(20).
05 PATIENT-NUMBER-IN PIC 99999.
05 PATIENT-NAME-IN PIC X(20).
05 SERVICE-IN PIC X(30).
05 DATE-IN PIC 9(8).
05 OWED-IN PIC 9(7)V99.
FD FILE-OUT.
01 REPORT-REC-OUT PIC X(100).
WORKING-STORAGE SECTION.
01 WS-WORK-AREAS.
05 WS-HOLD-HOSPITAL-NUM PIC 999 VALUE ZEROS.
05 WS-HOLD-PATIENT-NUM PIC 99999 VALUE ZEROS.
05 ARE-THERE-MORE-RECORDS PIC XXX VALUE 'YES'.
88 MORE-RECORDS VALUE 'YES'.
88 NO-MORE-RECORDS VALUE 'NO '.
05 FIRST-RECORD PIC XXX VALUE 'YES'.
05 WS-PATIENT-TOTAL PIC 9(9)V99 VALUE ZEROS.
05 WS-HOSPITAL-TOTAL PIC 9(9)V99 VALUE ZEROS.
05 WS-PAGE-CTR PIC 99 VALUE ZEROS.
01 WS-DATE.
05 WS-YR PIC 9999.
05 WS-MO PIC 99.
05 WS-DAY PIC 99.
01 HL-HEADING1.
05 PIC X(49) VALUE SPACES.
05 PIC X(14) VALUE 'OHIO INSURANCE'.
05 PIC X(7) VALUE SPACES.
05 HL-PAGE PIC Z9.
05 PIC X(14) VALUE SPACES.
05 HL-DATE.
10 HL-MO PIC 99.
10 PIC X VALUE '/'.
10 HL-DAY PIC 99.
10 PIC X VALUE '/'.
10 HL-YR PIC X VALUE '/'.
01 HL-HEADING2.
05 PIC XXXXXXXXXX VALUE 'HOSPITAL: '.
05 HL-HOSPITAL PIC 999.
01 HL-HEADING3.
05 PIC X(7) VALUE "Patient".
05 PIC X(3) VALUE SPACES.
05 PIC X(7) VALUE "Patient".
05 PIC X(39) VALUE SPACES.
05 PIC X(7) VALUE "Date of".
05 PIC X(3) VALUE SPACES.
05 PIC X(6) VALUE "Amount".
01 HL-HEADING4.
05 PIC X(6) VALUE "Number".
05 PIC X(4) VALUE SPACES.
05 PIC X(4) VALUE "Name".
05 PIC X(18) VALUE SPACES.
05 PIC X(10) VALUE "Service".
05 PIC X(14) VALUE SPACES.
05 PIC X(8) VALUE "Service".
05 PIC X(2) VALUE SPACES.
05 PIC X(5) VALUE "Owed".
01 DL-PATIENT-LINE.
05 PIC X(28) VALUE SPACES.
05 DL-PATIENT-NUMBER PIC XXXXX.
05 PIC X(21) VALUE SPACES.
05 DL-PATIENT-TOTAL PIC $$$,$$$,$$9.99.
01 DL-HOSPITAL-LINE.
05 PIC X(47) VALUE SPACES.
05 PIC X(16) VALUE 'HOSPITAL TOTAL: '.
05 DL-HOSPITAL-TOTAL PIC $$$,$$$,$$9.99.
PROCEDURE DIVISION.
100-MAIN-MODULE.
PERFORM 600-INITIALIZATION-RTN
PERFORM UNTIL NO-MORE-RECORDS
READ FILE-IN
AT END
MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 200-DETAIL-RTN
END-READ
END-PERFORM
PERFORM 400-HOSPITAL-BREAK
PERFORM 700-END-OF-JOB-RTN
STOP RUN.
200-DETAIL-RTN.
EVALUATE TRUE
WHEN FIRST-RECORD = 'YES'
MOVE PATIENT-NUMBER-IN TO WS-HOLD-PATIENT-NUM
MOVE HOSPITAL-NUMBER-IN TO WS-HOLD-HOSPITAL-NUM
PERFORM 500-HEADING-RTN
MOVE 'NO ' TO FIRST-RECORD
WHEN HOSPITAL-NUMBER-IN NOT = WS-HOLD-HOSPITAL-NUM
PERFORM 400-HOSPITAL-BREAK
WHEN PATIENT-NUMBER-IN NOT = WS-HOLD-PATIENT-NUM
PERFORM 300-PATIENT-BREAK
END-EVALUATE
ADD OWED-IN TO WS-PATIENT-TOTAL.
300-PATIENT-BREAK.
MOVE WS-PATIENT-TOTAL TO DL-PATIENT-TOTAL
MOVE WS-HOLD-PATIENT-NUM TO DL-PATIENT-NUMBER
WRITE REPORT-REC-OUT FROM DL-PATIENT-LINE
AFTER ADVANCING 2 LINES
ADD WS-PATIENT-TOTAL TO WS-HOSPITAL-TOTAL
IF MORE-RECORDS
MOVE ZEROS TO WS-PATIENT-TOTAL
MOVE PATIENT-NUMBER-IN TO WS-HOLD-PATIENT-NUM
END-IF.
400-HOSPITAL-BREAK.
PERFORM 300-PATIENT-BREAK
MOVE WS-HOSPITAL-TOTAL TO DL-HOSPITAL-TOTAL
WRITE REPORT-REC-OUT FROM DL-HOSPITAL-LINE
AFTER ADVANCING 2 LINES
IF MORE-RECORDS
MOVE ZEROS TO WS-HOSPITAL-TOTAL
MOVE HOSPITAL-NUMBER-IN TO WS-HOLD-HOSPITAL-NUM
PERFORM 500-HEADING-RTN
END-IF.
500-HEADING-RTN.
ADD 1 TO WS-PAGE-CTR
MOVE WS-PAGE-CTR TO HL-PAGE
MOVE WS-HOLD-HOSPITAL-NUM TO HL-HOSPITAL
WRITE REPORT-REC-OUT FROM HL-HEADING1
AFTER ADVANCING PAGE
WRITE REPORT-REC-OUT FROM HL-HEADING2
AFTER ADVANCING 2 LINES.
WRITE REPORT-REC-OUT FROM HL-HEADING3
AFTER ADVANCING 2 LINES.
600-INITIALIZATION-RTN.
OPEN INPUT FILE-IN
OUTPUT FILE-OUT
*159
ACCEPT WS-DATE FROM DATE YYYYMMDD
MOVE WS-YR TO HL-YR
MOVE WS-MO TO HL-MO
MOVE WS-DAY TO HL-DAY.
700-END-OF-JOB-RTN.
CLOSE FILE-IN
FILE-OUT.