Having difficulty outputting a report



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Having difficulty outputting a report

Postby maverik877 » Thu Apr 04, 2013 11:52 pm

Hello everyone,

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


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.


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.
maverik877
 
Posts: 3
Joined: Thu Apr 04, 2013 11:40 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Having difficulty outputting a report

 

Re: Having difficulty outputting a report

Postby Robert Sample » Fri Apr 05, 2013 12:07 am

This code
           set I-Hospital-Entry to 0
           set I-Patient-Entry to 0
needs to be moved to your 100-INITIALIZE paragraph. Your 300-process praragraph should instead have
            set I-Hospital-Entry up by 1.
            set I-Patient-Entry up by 1.
You are moving data to the zeroth element of the array, which does not exist in COBOL (which in turn means you are overwriting storage).

There are undoubtedly other issues (such as patient index and hospital index probably BOTH should not be incremented for every record), but that should get you something printed to review.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times

Re: Having difficulty outputting a report

Postby BillyBoyo » Fri Apr 05, 2013 12:59 am

You're not using an IBM Cobol, are you? On ours, you can't SET an index to zero.

You're supposed to have SET those to the incoming hospital and patient numbers, not to zero.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Having difficulty outputting a report

Postby maverik877 » Fri Apr 05, 2013 3:03 am

I made the changes you suggested, moving the I-Hospital-Entry and I-Patient-Entry to the initialization paragraph and set them both to 1. I also moved both of their values up by 1 after the series of move statements in 300-Process. Everything compiles fine, I go to click on the .exe file like I usually do to run the program in order to update my out file, but I get a message telling me the .exe has stopped working. Right now I'm trying to double check index values in different places to make sure I didn't do something wrong. :? I will get to the bottom of this!
maverik877
 
Posts: 3
Joined: Thu Apr 04, 2013 11:40 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Having difficulty outputting a report

Postby BillyBoyo » Fri Apr 05, 2013 3:21 am

Undo the changes and read what I wrote.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Having difficulty outputting a report

Postby Robert Sample » Fri Apr 05, 2013 4:51 am

Scrap everything you've done and start over. Develop a good, solid description of the problem before you begin coding -- premature coding causes many beginners problems. A start on your design:
Open files
Read a record
Search the hospital table for the hospital number
if  hospital number not in table
    if  hospital table is full
        display hospital table full message
        close files
        stop run
   else
        add hospital to table
        add patient to first table entry
    endif
else
    search patient table for the patient number
    if  patient number is not in table
        if  patient talbe is full
            display patient table full message
            close files
            stop  run
        else
             add 1 to hospital patient count
             move patient data to patient table (hospital patient count)
        endif
    else
        add data to current patient number
    endif
endif
This is not everything you need to consider (and does not cover getting the report out), but it is a start.

Suggestion: use short varaible names for indexes -- you will be using them a lot and shortened names are easier to key as well as understand (your code requires a reference to HA-Hospital-Entry (I-Hospital-Entry) which is redundant and confusing).

           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
This code won't do what you want (12 AM will not appear as 12 AM) -- and is needlessly complicated. Something like
EVALUATE TRUE
WHEN (SYS-HOUR < 12)
    MOVE 'AM' TO AM-PM
WHEN (12 < SYS-HOUR AND SYS-HOUR <24)
    MOVE 'PM' TO AM-PM
    SUBTRACT 12 FROM SYS-HOUR
WHEN (SYS-HOUR = 24)
    MOVE 'AM' TO AM-PM
    MOVE 12 TO SYS-HOUR
END-EVALUATE.
will provide the results you want as well as be easier to understand and maintain.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times

Re: Having difficulty outputting a report

Postby BillyBoyo » Fri Apr 05, 2013 5:19 am

Hospital numbers are 1 to 30. Patient number are 1 to 20.

The task is to list output in order by Hospital number, Patient number, with an unsorted input file.

I don't know what either of you are doing with the time. Over on this side of the "pond", 12 AM is midday, 12 PM is midnight. Use 88s.

88  time-is-am value zero thru 1200.
88  time-is-pm value 1201 thru 2400.

IF time-is-am
    MOVE 'AM' TO AM-PM
ELSE
    MOVE 'PM TO AM-PM
    SUBTRACT 12 FROM SYS-HOUR
END-IF


Bear in mind that 24:00 is 00:00 and may, or may not, actually exist in the source for the time anyway. Probably 23:59 kicks over to 00:00.

I'd not actually SUBTACT from SYS-HOUR itself - if you do, and your program fails and you get a memory dump, you'll never be quite sure what value SYS-HOUR had originally.

Long index/subscript names are fine. Saves getting subsa mixed up with suba. Typing is no problem, you only do it once.

There is a lot of "personal preference" in coding :-)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Having difficulty outputting a report

Postby maverik877 » Fri Apr 05, 2013 5:32 am

Thank you very much for your help. I think I sort of got ahead of myself and just started coding without fully understanding the problem. I have a file containing hospital and patient information. I figure, if I can read that data in, put it into a table, then I should be able to print these out in a sorted order grouped by hospital number. Since I also need to print out a subtotal for each hospital, perhaps this can be done by keeping track of the changing hospital number. If it does not change print out a patient detail line, if it does change this means the given hospital is done and it's time to print the subtotal, etc.

Thanks again.

Actually on the time output, although it looks convoluted, this has actually worked on a report for me before. :o I am in Eastern standard time zone, United States.
maverik877
 
Posts: 3
Joined: Thu Apr 04, 2013 11:40 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Having difficulty outputting a report

Postby BillyBoyo » Fri Apr 05, 2013 6:02 am

Well, that's one to watch whilst travelling :-) I should make a note not to arrive in the US between 00:00 and 00:59 as I'll not even know which day of the week it is. You really call that 12:01 AM?

I'm glad I've never had to put AM/PM on a report. Thinking about it now, I'd not even like to say I'm sure that we don't call it 12:01 AM. How'm I going to check that? Needs someone older than me who never mastered the 24hr Clock.

Anyway, it is not so much what you want to call the time, but how easy the code is to follow. An EVALUATE is better than a "nested" IF.

And you should look at the top left of the screen on this site.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Having difficulty outputting a report

Postby NicC » Fri Apr 05, 2013 6:12 pm

You should also note that this is a mainframe site - not a PC site so, technically you should not have posted here. Technically it should be locked and the keys thrown away but as 2 other moderators have spent time on it I will leave it open. But, in future please only post mainframe stuff.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2690
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post