I am trying to follow an example I found in a cobol book to print out a detailed report but nothing is actually printing out and I am not sure why. I have an input file filled with hospital and patient data where some of the file might look like this:
001Riverside Methodist 00004Esther, Polly 70 Retro Way Chicago IL 02141987002548150
001Riverside Methodist 00012Time, Justin 900 E Maple Pittsburgh PA 01012000002501480
002Dr Butcher Clinic 00002Wong, Sum-Ting 14 Oak St Columbus OH 05101993000145410
001Riverside Methodist 00012Time, Justin 900 E Maple Pittsburgh PA 01012000002501480
002Dr Butcher Clinic 00002Wong, Sum-Ting 14 Oak St Columbus OH 05101993000145410
There are multiple hospitals with patients and I am trying to read everything in from a file that is not organized and use a table to print it in a sorted manner grouped by hospital number. I wrote code which I think is close to working but nothing is written to the report except the header and I am not sure why. If anyone could help me with this issue of explain to me why nothing is outputted to my report file, I would be very appreciate! Any help at all would be a huge plus.
Here is my code. It's kind of long.
identification division.
program-id. lab7b.
environment division.
input-output section.
file-control.
select in-hospitals assign to "lab7b-in.dat"
organization is line sequential.
select out-report assign to "lab7b-out.dat"
organization is line sequential.
data division.
file section.
fd in-hospitals.
01 in-rec.
05 in-hos-num PIC 9(3).
05 in-hos-name PIC x(20).
05 in-pat-num PIC 9(5).
05 in-pat-name PIC x(20).
05 in-pat-add PIC x(30).
05 in-pat-serv-dt PIC 9(8).
05 in-pat-amnt-od PIC 9(7)v99.
fd out-report.
01 out-record PIC x(100).
working-storage section.
* variables for EOF of insurance and hospitals
01 END-OF-FILE-SW PIC x value "N".
01 report-fields.
05 page-num PIC 9(3) value 0.
05 lines-page PIC 9(2) value 35.
05 line-num PIC 9(2) value 99.
* variables to get date for top of page
01 ws-date.
05 ws-year PIC 9(4).
05 ws-month PIC 99.
05 ws-day PIC 99.
* variables relating to current time, blank line for report
* formatting, num-patients for average calculation, and other
* variables are for getting things like time and date before
* passing them on to better format
01 HospArray value spaces.
05 FILLER occurs 30 times
indexed by I-Hospital-Entry.
10 HA-Hospital-Entry.
15 HA-Hospital-Number pic xxx.
88 HA-hospital-not-present
VALUE SPACE.
15 FILLER occurs 20 times
indexed by I-Patient-Entry.
20 HA-Patient-Entry.
25 HA-Patient-Number pic xxxxx.
88 HA-Patient-not-present
VALUE SPACE.
25 HA-Patient-Name PIC X(20).
25 HA-Patient-Payment-Amount PIC 9(7)v99.
01 hos-num-ws PIC 9(3).
01 hos-name-ws PIC x(20).
01 pat-num-ws PIC 9(5).
01 pat-name-ws PIC x(20).
01 pat-add-ws PIC x(30).
01 pat-serv-dt-ws PIC 9(8).
01 pat-amnt-od-ws PIC 9(7)v99.
01 first-rec-count PIC 9(4).
01 pat-per-hos-temp PIC 9(5).
01 last-hos-nme PIC x(20).
01 pat-per-hos PIC 9(5).
01 hos-sub-bal PIC 9(7)v99.
01 high-hos-sub-bal PIC 9(7)v99.
01 hos-group-avg PIC 9(7)v99.
01 hos-group-tot PIC 9(7)v99.
01 total-outs-bal PIC 9(9)v99.
01 average-outs-bal PIC 9(8)v99.
01 highest-outs-bal PIC 9(8)v99.
01 num-patients PIC 9(5).
01 num-subtotals PIC 9(5).
01 count-outst-prev PIC 9(7)v99.
01 blank-line pic x(100) value spaces.
01 sys-hour pic 9(2).
01 get-time pic x(8).
01 date-for-reg pic x(8).
01 subsc pic 99.
01 W-Patient-Name PIC x(20).
01 Patient-Payment-Amount PIC 9(7)v99.
01 Hospital-Number.
05 Hospital-Number-N PIC 999 value 0.
01 Patient-Number.
05 Patient-Number-N PIC 999 value 0.
01 Hospital-Sub-Total PIC 9(7)v99.
01 page-header.
05 ph-month PIC z9/.
05 ph-day PIC 99/.
05 ph-year PIC 9999.
05 PIC x(19) value spaces.
05 PIC x(35) value "VaporCare Regional" &
"Health Insurance".
05 PIC x(26) value spaces.
05 PIC x(6) value "Page: ".
05 ph-page-num PIC zz9.
05 PIC x(13) value spaces.
* The second page header for subtitle, date, and time
01 page-header-2nd-ln.
05 PIC x(3) value spaces.
05 time-format.
07 hour PIC z9.
07 colon PIC x value ":".
07 minutes PIC 99.
07 AM-PM PIC X(2).
05 PIC x(26) value spaces.
05 PIC x(35) value "Summary of " &
"Outstanding Balances".
05 PIC x(10) value spaces.
01 col-header.
05 pic x(15) value "Patient #".
05 pic x(25) value "Patient Name".
05 pic x(22) value "Amount Owed".
01 hospital-sub-headone.
05 pic x(4) value spaces.
05 pic x(17) value "Hospital " &
"Number:".
05 pic x(4) value spaces.
05 hos-region-num pic 9(3).
01 hospital-sub-headtwo.
05 pic x(4) value spaces.
05 pic x(21) value "Hospital " &
"Name:".
05 hos-name-sub pic x(20).
05 pic x(4) value spaces.
01 detail-line.
05 dl-pat-num pic 9(5).
05 pic x(9) value spaces.
05 dl-pat-name pic x(20).
05 pic x(12) value spaces.
05 dl-balance pic $$$,$$$,$$$.99.
05 pic x(13) value spaces.
01 hospital-subtwo.
05 pic x(4) value spaces.
05 pic x(35) value "Total Amount " &
"Owed for Hospital: ".
05 pic x(5) value spaces.
05 sub-tot-amnt-perhos pic $$$,$$$,$$$,$$9.99.
05 pic x(13) value spaces.
01 total-line-one.
05 pic x(70) value "Total Outstanding" &
" Balance for VaporCare".
05 pic x(15) value spaces.
05 tl-outs-bal pic $$$,$$$,$$$.99.
05 pic x(13) value spaces.
01 control-fields.
05 last-hos pic 9(3) value low-values.
procedure division.
000-main.
perform 100-initialize
perform until END-OF-FILE-SW = "y"
read in-hospitals
at end
move "y" to END-OF-FILE-SW
not at end
perform 300-process
end-read
end-perform
perform 800-print
perform 900-finalize
stop run.
* do initial tasks, open files, get date.
100-initialize.
perform 110-open-files
perform 120-get-date.
110-open-files.
open input in-hospitals
output out-report.
120-get-date.
accept ws-date from date yyyymmdd
move ws-year to ph-year
move ws-month to ph-month
move ws-day to ph-day.
* Adding 1 to num-patients to eventually
* be able to calculate the average outstanding amnt.
300-process.
add 1 to first-rec-count
move in-hos-num to hos-num-ws
move in-hos-name to hos-name-ws
move in-pat-num to pat-num-ws
move in-pat-name to pat-name-ws
move in-pat-add to pat-add-ws
move in-pat-serv-dt to pat-serv-dt-ws
move in-pat-amnt-od to pat-amnt-od-ws
set I-Hospital-Entry to 0
set I-Patient-Entry to 0
move in-hos-num to HA-Hospital-Number (I-Hospital-Entry)
move in-hos-name to hos-name-ws
move in-pat-num to HA-Patient-Number
( I-Hospital-Entry I-Patient-Entry)
move in-pat-name to W-Patient-Name
move W-Patient-Name to HA-Patient-Name
( I-Hospital-Entry I-Patient-Entry)
move in-pat-amnt-od to Patient-Payment-Amount
move Patient-Payment-Amount
to HA-Patient-Payment-Amount
( I-Hospital-Entry I-Patient-Entry).
800-print.
if line-num > lines-page
perform 825-new-page
end-if
perform
varying I-Hospital-Entry
from 1 by 1 until I-Hospital-Entry > 30
if HA-hospital-not-present
( I-Hospital-Entry)
continue
else
perform LIST-PATIENTS
move Hospital-Sub-Total to
sub-tot-amnt-perhos
write out-record from blank-line
write out-record from
hospital-subtwo
end-if
move HA-Hospital-Number
(I-Hospital-Entry)
to Hospital-Number
end-perform.
LIST-PATIENTS.
perform varying I-Patient-Entry
from 1 by 1 until I-Patient-Entry > 20
if HA-hospital-not-present ( I-Hospital-Entry)
continue
else
perform PATIENT-DETAILS
end-if
move Hospital-Sub-Total to
sub-tot-amnt-perhos
write out-record from blank-line
write out-record from
hospital-subtwo
end-perform.
PATIENT-DETAILS.
move HA-Patient-Name(I-Hospital-Entry, I-Patient-Entry)
to W-Patient-Name
move HA-Patient-Payment-Amount
(I-Hospital-Entry, I-Patient-Entry)
to Patient-Payment-Amount
add Patient-Payment-Amount to Hospital-Sub-Total.
move HA-Patient-Number
(I-Hospital-Entry, I-Patient-Entry)
to dl-pat-num
move W-Patient-Name to dl-pat-name
move Patient-Payment-Amount to dl-balance
write out-record from blank-line
write out-record from detail-line.
825-new-page.
add 1 to page-num
move page-num to ph-page-num
accept get-time from time
unstring get-time
into sys-hour minutes
end-unstring
* This was one of the most interesting parts of
* the program. Taking care of the AMPM and converting
* military time to civilian time by checking if
* hours was >= 13. If it is go back 12. Example if
* the time was 15:30PM it is really 3:30PM
if sys-hour < 12
move "AM" to AM-PM
else
move "PM" to AM-PM
if sys-hour >= 13
subtract 12 from sys-hour
end-if
end-if
if sys-hour = 0 and AM-PM = "AM"
set sys-hour to 12
end-if
move sys-hour to hour
write out-record from blank-line
write out-record from blank-line
write out-record from page-header
write out-record from page-header-2nd-ln
after advancing page
write out-record from blank-line
after advancing 1 line
write out-record from col-header
after advancing 1 line
write out-record from blank-line
after advancing 1 line
* ADDED IN 337
move 4 to line-num.
900-finalize.
perform 999-close-files.
950-print-grand-total.
write out-record from blank-line
after advancing 1 line
add 1 to line-num
if line-num > lines-page
perform 825-new-page
end-if
move total-outs-bal to tl-outs-bal
* outputing the ending lines in a good format with
* blank lines where needed.
write out-record from blank-line
write out-record from total-line-one.
999-close-files.
close in-hospitals out-report.
program-id. lab7b.
environment division.
input-output section.
file-control.
select in-hospitals assign to "lab7b-in.dat"
organization is line sequential.
select out-report assign to "lab7b-out.dat"
organization is line sequential.
data division.
file section.
fd in-hospitals.
01 in-rec.
05 in-hos-num PIC 9(3).
05 in-hos-name PIC x(20).
05 in-pat-num PIC 9(5).
05 in-pat-name PIC x(20).
05 in-pat-add PIC x(30).
05 in-pat-serv-dt PIC 9(8).
05 in-pat-amnt-od PIC 9(7)v99.
fd out-report.
01 out-record PIC x(100).
working-storage section.
* variables for EOF of insurance and hospitals
01 END-OF-FILE-SW PIC x value "N".
01 report-fields.
05 page-num PIC 9(3) value 0.
05 lines-page PIC 9(2) value 35.
05 line-num PIC 9(2) value 99.
* variables to get date for top of page
01 ws-date.
05 ws-year PIC 9(4).
05 ws-month PIC 99.
05 ws-day PIC 99.
* variables relating to current time, blank line for report
* formatting, num-patients for average calculation, and other
* variables are for getting things like time and date before
* passing them on to better format
01 HospArray value spaces.
05 FILLER occurs 30 times
indexed by I-Hospital-Entry.
10 HA-Hospital-Entry.
15 HA-Hospital-Number pic xxx.
88 HA-hospital-not-present
VALUE SPACE.
15 FILLER occurs 20 times
indexed by I-Patient-Entry.
20 HA-Patient-Entry.
25 HA-Patient-Number pic xxxxx.
88 HA-Patient-not-present
VALUE SPACE.
25 HA-Patient-Name PIC X(20).
25 HA-Patient-Payment-Amount PIC 9(7)v99.
01 hos-num-ws PIC 9(3).
01 hos-name-ws PIC x(20).
01 pat-num-ws PIC 9(5).
01 pat-name-ws PIC x(20).
01 pat-add-ws PIC x(30).
01 pat-serv-dt-ws PIC 9(8).
01 pat-amnt-od-ws PIC 9(7)v99.
01 first-rec-count PIC 9(4).
01 pat-per-hos-temp PIC 9(5).
01 last-hos-nme PIC x(20).
01 pat-per-hos PIC 9(5).
01 hos-sub-bal PIC 9(7)v99.
01 high-hos-sub-bal PIC 9(7)v99.
01 hos-group-avg PIC 9(7)v99.
01 hos-group-tot PIC 9(7)v99.
01 total-outs-bal PIC 9(9)v99.
01 average-outs-bal PIC 9(8)v99.
01 highest-outs-bal PIC 9(8)v99.
01 num-patients PIC 9(5).
01 num-subtotals PIC 9(5).
01 count-outst-prev PIC 9(7)v99.
01 blank-line pic x(100) value spaces.
01 sys-hour pic 9(2).
01 get-time pic x(8).
01 date-for-reg pic x(8).
01 subsc pic 99.
01 W-Patient-Name PIC x(20).
01 Patient-Payment-Amount PIC 9(7)v99.
01 Hospital-Number.
05 Hospital-Number-N PIC 999 value 0.
01 Patient-Number.
05 Patient-Number-N PIC 999 value 0.
01 Hospital-Sub-Total PIC 9(7)v99.
01 page-header.
05 ph-month PIC z9/.
05 ph-day PIC 99/.
05 ph-year PIC 9999.
05 PIC x(19) value spaces.
05 PIC x(35) value "VaporCare Regional" &
"Health Insurance".
05 PIC x(26) value spaces.
05 PIC x(6) value "Page: ".
05 ph-page-num PIC zz9.
05 PIC x(13) value spaces.
* The second page header for subtitle, date, and time
01 page-header-2nd-ln.
05 PIC x(3) value spaces.
05 time-format.
07 hour PIC z9.
07 colon PIC x value ":".
07 minutes PIC 99.
07 AM-PM PIC X(2).
05 PIC x(26) value spaces.
05 PIC x(35) value "Summary of " &
"Outstanding Balances".
05 PIC x(10) value spaces.
01 col-header.
05 pic x(15) value "Patient #".
05 pic x(25) value "Patient Name".
05 pic x(22) value "Amount Owed".
01 hospital-sub-headone.
05 pic x(4) value spaces.
05 pic x(17) value "Hospital " &
"Number:".
05 pic x(4) value spaces.
05 hos-region-num pic 9(3).
01 hospital-sub-headtwo.
05 pic x(4) value spaces.
05 pic x(21) value "Hospital " &
"Name:".
05 hos-name-sub pic x(20).
05 pic x(4) value spaces.
01 detail-line.
05 dl-pat-num pic 9(5).
05 pic x(9) value spaces.
05 dl-pat-name pic x(20).
05 pic x(12) value spaces.
05 dl-balance pic $$$,$$$,$$$.99.
05 pic x(13) value spaces.
01 hospital-subtwo.
05 pic x(4) value spaces.
05 pic x(35) value "Total Amount " &
"Owed for Hospital: ".
05 pic x(5) value spaces.
05 sub-tot-amnt-perhos pic $$$,$$$,$$$,$$9.99.
05 pic x(13) value spaces.
01 total-line-one.
05 pic x(70) value "Total Outstanding" &
" Balance for VaporCare".
05 pic x(15) value spaces.
05 tl-outs-bal pic $$$,$$$,$$$.99.
05 pic x(13) value spaces.
01 control-fields.
05 last-hos pic 9(3) value low-values.
procedure division.
000-main.
perform 100-initialize
perform until END-OF-FILE-SW = "y"
read in-hospitals
at end
move "y" to END-OF-FILE-SW
not at end
perform 300-process
end-read
end-perform
perform 800-print
perform 900-finalize
stop run.
* do initial tasks, open files, get date.
100-initialize.
perform 110-open-files
perform 120-get-date.
110-open-files.
open input in-hospitals
output out-report.
120-get-date.
accept ws-date from date yyyymmdd
move ws-year to ph-year
move ws-month to ph-month
move ws-day to ph-day.
* Adding 1 to num-patients to eventually
* be able to calculate the average outstanding amnt.
300-process.
add 1 to first-rec-count
move in-hos-num to hos-num-ws
move in-hos-name to hos-name-ws
move in-pat-num to pat-num-ws
move in-pat-name to pat-name-ws
move in-pat-add to pat-add-ws
move in-pat-serv-dt to pat-serv-dt-ws
move in-pat-amnt-od to pat-amnt-od-ws
set I-Hospital-Entry to 0
set I-Patient-Entry to 0
move in-hos-num to HA-Hospital-Number (I-Hospital-Entry)
move in-hos-name to hos-name-ws
move in-pat-num to HA-Patient-Number
( I-Hospital-Entry I-Patient-Entry)
move in-pat-name to W-Patient-Name
move W-Patient-Name to HA-Patient-Name
( I-Hospital-Entry I-Patient-Entry)
move in-pat-amnt-od to Patient-Payment-Amount
move Patient-Payment-Amount
to HA-Patient-Payment-Amount
( I-Hospital-Entry I-Patient-Entry).
800-print.
if line-num > lines-page
perform 825-new-page
end-if
perform
varying I-Hospital-Entry
from 1 by 1 until I-Hospital-Entry > 30
if HA-hospital-not-present
( I-Hospital-Entry)
continue
else
perform LIST-PATIENTS
move Hospital-Sub-Total to
sub-tot-amnt-perhos
write out-record from blank-line
write out-record from
hospital-subtwo
end-if
move HA-Hospital-Number
(I-Hospital-Entry)
to Hospital-Number
end-perform.
LIST-PATIENTS.
perform varying I-Patient-Entry
from 1 by 1 until I-Patient-Entry > 20
if HA-hospital-not-present ( I-Hospital-Entry)
continue
else
perform PATIENT-DETAILS
end-if
move Hospital-Sub-Total to
sub-tot-amnt-perhos
write out-record from blank-line
write out-record from
hospital-subtwo
end-perform.
PATIENT-DETAILS.
move HA-Patient-Name(I-Hospital-Entry, I-Patient-Entry)
to W-Patient-Name
move HA-Patient-Payment-Amount
(I-Hospital-Entry, I-Patient-Entry)
to Patient-Payment-Amount
add Patient-Payment-Amount to Hospital-Sub-Total.
move HA-Patient-Number
(I-Hospital-Entry, I-Patient-Entry)
to dl-pat-num
move W-Patient-Name to dl-pat-name
move Patient-Payment-Amount to dl-balance
write out-record from blank-line
write out-record from detail-line.
825-new-page.
add 1 to page-num
move page-num to ph-page-num
accept get-time from time
unstring get-time
into sys-hour minutes
end-unstring
* This was one of the most interesting parts of
* the program. Taking care of the AMPM and converting
* military time to civilian time by checking if
* hours was >= 13. If it is go back 12. Example if
* the time was 15:30PM it is really 3:30PM
if sys-hour < 12
move "AM" to AM-PM
else
move "PM" to AM-PM
if sys-hour >= 13
subtract 12 from sys-hour
end-if
end-if
if sys-hour = 0 and AM-PM = "AM"
set sys-hour to 12
end-if
move sys-hour to hour
write out-record from blank-line
write out-record from blank-line
write out-record from page-header
write out-record from page-header-2nd-ln
after advancing page
write out-record from blank-line
after advancing 1 line
write out-record from col-header
after advancing 1 line
write out-record from blank-line
after advancing 1 line
* ADDED IN 337
move 4 to line-num.
900-finalize.
perform 999-close-files.
950-print-grand-total.
write out-record from blank-line
after advancing 1 line
add 1 to line-num
if line-num > lines-page
perform 825-new-page
end-if
move total-outs-bal to tl-outs-bal
* outputing the ending lines in a good format with
* blank lines where needed.
write out-record from blank-line
write out-record from total-line-one.
999-close-files.
close in-hospitals out-report.
Hopefully with this formatting you can tell what the program is doing. It will find a hospital number and print patients and their dollar amounts repeatedly. Also, in the file, the range for hospital numbers is between 1 and 30 and the range for patient numbers is between 1 and 20.