getting unwanted output in cobol program

124 views Asked by At

Ok this is my first ever post here and this is the part where I am stuck. I am taking an input file and outputting a list of errors, One of the parts that I have to do is for a school district which is a string of 3. In the procedure division I have perform B-Paragraph perform C-Paragraph

B-Paragraph is where all the other errors are found because they really just require 1 if statement.

C-Paragraph is the school district part. It checks if School District is not of a valid format. It is only valid if:

  • all 3 characters are spaces; or
  • the first two characters are numbers, and:
    • if they are the same, the 3rd character cannot be a number; or
    • if they are not the same, then one of them must be odd and the other even.

In the working storage section I have school district listed as

05 District.
             
    10 DistrictA     PIC 9.
              
    10 DistrictB     PIC 9.
              
    10 DistrictC     PIC 9.

and then in the C-paragraph section I have

            if DistrictA <> " " and DistrictB <> " " 
                and DistrictC <> " "
              write ot-records from 
                "School District is not valid:"
                add 1 to Counter
                  Exit Paragraph
                End-if.

            if DistrictA is not numeric or DistrictB is not numeric
            write ot-records from 
                "School District is not valid:"
                add 1 to Counter 
                  Exit Paragraph
                    End-if.

            if DistrictA = DistrictB
                if DistrictC is numeric
                    write ot-records from 
                "School District is not valid:"
                add 1 to Counter
                  Exit Paragraph
                    End-if
                    Else if DistrictA <> DistrictB and 
                    (DistrictA + DistrictA) / 2   = 0 and 
                    (DistrictB + DistrictB) / 2   <> 0 
                    write ot-records from 
                "School District is not valid:"
                add 1 to Counter
                 Exit Paragraph.

from the output it's saying the "school district is not valid" for every file. So the final count is larger than it should be.

1

There are 1 answers

0
Simon Sobisch On BEST ANSWER

There is a logic flow in your code. In the case "all three are not spaces" you exit directly in the first IF, in the case "all three are spaces" you always exit in the second IF (because first two spaces -> never numeric).

You likely want to either combine multiple entries or make the code easier by reversing the logic -> only exit the paragraph if the district is valid and in the very last place have the error handling (which is useful in any case as you have the same code exactly once, so no option for typos in one of the three or other harder to spot bugs, and easier to adjust later).

Depending on the task you may want to use level 88 items to check for some/all of the conditions, that way they are directly attached to the variables.