2

I am still new to COBOL and have been working on a project for school for almost a week now. I am running OpenCobol 1.1. When I try to compile it I get this error.

typeck.c:5912: Invalid type cast from 'null'
Tag 1 0 Tag 2 10
Aborting compile of lab4.cob at line 214

I've been frustrated because I've tried changing the code around a lot with no luck.

Procedure Division.
   000-Main.
        Perform 100-initialize

        Perform Until EndOfFile = "Y"
           Read Lab4-in-File
              At End
                 Move "Y" To EndOfFile
              Not At End
                 Perform 300-process
           End-Read
        End-Perform

        Perform 900-finalize

        Stop Run.

   100-intialize.
       Perform 110-open-files
       Perform 120-get-data.

   110-open-files.
       Open Input Lab4-in-File
          Output Ot-File.

   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.

   300-process.
       Move Dept-no To dl-dep-no
       Move Employee-no To dl-emp-no
       If First-name Not = "Null"
          String First-name Delimited By Size
                " " Delimited By Size
                Last-name Delimited By Size 
                Into dl-emp
       else 
          Move Last-name To dl-emp
       End-If     
       Move Job-title To dl-job
       Move DOH To dl-doh
       Move Mar-status To dl-marital
       Move Dependents To dl-dependents
       Move MCoverage To dl-insurance
       Move DCoverage To dl-insurance
       Move VCoverage To dl-insurance
       Move 401K To dl-401k
       Move Pay-code To dl-pay-code
       If Pay-code = "C" Or "S"
          Compute Pay-hold rounded = 
               Pay / 12
          Move Pay-hold To dl-monthly-pay
       else
          Compute Pay-hold rounded =
               Pay * HPW * 4
          Move Pay-hold To dl-monthly-pay
       End-If

       If Pay-code = "C"
          Compute Com-hold rounded =
               Act-sale * C-rate
          Move Com-hold To dl-commission
       Else
          Move 0 To dl-commission
       End-If

       Perform 800-print

       Multiply C-rate By Act-sale Giving 
           total-sales

       Add Pay To total-sales.

   800-print.
       If LineNum > LinesPerPage
          Perform 825-new-page
       End-If

       Write Lab4-Record2 From Detail-Line
            **After advancing 1 line**     *> This is line 214     

       Add 1 To LineNum.

   825-new-page.
       If PageNum > 0
          Write Lab4-Record2 From Blank-line
              After advancing 1 line
       End-If

       Add 1 To PageNum
       Move PageNum To PH-PageNo

       Write Lab4-Record2 From Page-Header
           After advancing page

       Write Lab4-Record2 From Blank-line
           After advancing 1 line

       Write Lab4-Record2 From Column-Header
           After advancing 1 line

       Write Lab4-Record2 From Blank-line
           After advancing 1 line

       Move 5 To LineNum.

   900-finalize.
       Perform 950-print-monthly-total
       Perform 999-close-files.

   950-print-monthly-total.
       If LineNum + 1 > LinesPerPage
          Perform 825-new-page
       End-If

       Write Lab4-Record2 From Blank-line
           After advancing 1 line

       Move total-sales To Total-pay

       Write Lab4-Record2 From Total-Line
           After advancing 1 line

       Add 2 To LineNum.

   999-close-files.
       Close Lab4-in-File Ot-File.

I would really appreciate it if someone could help me find what is causing the error. Thanks in advance!

Working-Storage Section.
   01  EndOfFile        Pic X Value "N".

   01  Report-fields.
       05  PageNum           Pic 9(3)  value 0.
       05  LinesPerPage      Pic 9(2)  value 40.
       05  LineNum           Pic 9(2)  value 41.

   01  WS-date.
       05  WS-Year           Pic 9(4).
       05  WS-Month          Pic 99.
       05  WS-Day            Pic 99.

   01  total-fields. 
       05  total-sales       Pic 9(11)v99 Value 0.

   01  Page-Header.
       05  PH-Month          Pic Z9/.
       05  PH-Day            Pic 99/.
       05  PH-Year           Pic 9999.
       05                    Pic X(7) Value Spaces.
       05                    Pic X(29) Value "Stomper &" &
                                 " Wombat's Emporium"
       05                    Pic X(6) Value "Page:".
       05  PH-PageNo         Pic ZZ9.

   01  Column-Header.
       05                    Pic X(8) Value "Dep #".
       05                    Pic X(15) Value "Emp #".
       05                    Pic X(27) Value "Employee".
       05                    Pic X(18) Value "Title".
       05                    Pic X(9) Value "DOH".
       05                    Pic X(9) Value "Marital".
       05                    Pic X(7) Value "#Deps".
       05                    Pic X(6) Value "Ins".
       05                    Pic X(6) Value "401K".
       05                    Pic X(6) Value "Pay".
       05                    Pic X(27) Value "Expected " &
                                  "Pay  +  Commission".

   01  Pay-hold              Pic 9(9)V9(2) Value 0.    
   01  Com-hold              Pic 9(9)V9(2) Value 0.

   01  Detail-Line.
       05  dl-dep-no         Pic X(5).
       05                    Pic X(1) Value spaces.
       05  dl-emp-no         Pic X(5).
       05                    Pic X(1) Value spaces.
       05  dl-emp            Pic X(35).
       05                    Pic X(1) Value spaces.
       05  dl-job            Pic X(20).
       05                    Pic X(1) Value spaces.
       05  dl-doh            Pic X(8).
       05                    Pic X(1) Value spaces.
       05  dl-marital        Pic X.
       05                    Pic X(1) Value spaces.
       05  dl-dependents     Pic 9(2).
       05                    Pic X(1) Value spaces.
       05  dl-insurance      Pic X(3).
       05                    Pic X(1) Value spaces.
       05  dl-401k           Pic Z.9ZZ.
       05                    Pic X(1) Value spaces.
       05  dl-pay-code       Pic X.
       05                    Pic X(1) Value spaces.
       05  dl-monthly-pay    Pic $$$$,$$$,$$9.99.
       05                    Pic X(1) Value spaces.
       05  dl-commission     Pic $$$,$$9.99.


   01  Total-Line.
       05                    Pic X(61) Value Spaces.
       05                    Pic X(24) Value "Total" & 
       " Expected Payroll: ".
       05  Total-pay         Pic $$$$,$$$,$$$,$$9.99.

   01  Blank-line            Pic X Value spaces.
Matt Kane
  • 23
  • 3
  • What if the definition of First-name, which is line 214 and what is the working storage and finally which version of GNU-Cobol are you using – Bruce Martin Oct 11 '18 at 05:22
  • The First-name is a Pic X(15), line 214 is in paragraph 800-print the After advancing 1 line, I just updated the post with the working storage, and I'm using version 1.1. – Matt Kane Oct 11 '18 at 06:43

1 Answers1

4

The compiler has a broken parser. It is broken because of a coding error (still a compiler bug). In cases like this you only have the chance to either spot the error or - much better - use a newer version.

I've just put your code in an online compiler using the last release of the compiler: GnuCOBOL 2.2. I highly suggest to upgrade to at least this version.

See your code here - I've just added a minimal header and end.
Then click on "Execute" and you compile it online, leading to the following error messages:

main.cobc: 27: error: duplicate PICTURE clause
main.cobc: 27: error: duplicate VALUE clause
main.cobc: 64: error: a Z or * which is after the decimal point cannot follow 9

If you check the line 27 in this program you see

   05                    Pic X(29) Value "Stomper &" &
                            " Wombat's Emporium"   *>   <<- missing period
   05                    Pic X(6) Value "Page:".

Fixed code is also available.

Simon Sobisch
  • 6,263
  • 1
  • 18
  • 38
  • Thank you so much! – Matt Kane Oct 11 '18 at 20:03
  • @MattKane if the answer "worked" for you: please "accept" and upvote it. If the bad error that tripped the compiler wasn't the missing period (I did not back and checked the old compiler) upvote and add an answer your own + accept this. And in any case: tell your school to update the free compiler to its latest version :-) – Simon Sobisch Oct 11 '18 at 20:52
  • It definitely helped fix up the problem! They definitely need to update haha. – Matt Kane Oct 12 '18 at 04:25