1

I'm trying to create a report for a given input file where I am supposed to ill examine each record to determine if it fails to meet certain criteria. The issue that I am facing now is that the cob file wont compile eventhough it doesn't explicitly show any errors when compiling it on the command window and the executable doesn't get created. I was wondering if any of you could help me figure out where the error lies in my code.

Identification Division.
   Program-ID. lab5.

   Environment Division.
   Input-Output Section.
   File-Control.
       Select PayrollFile
       Assign to "lab5-in.dat"
       Organization is Line Sequential.
       Select OutputReport
       Assign to "lab5-out.dat"
       Organization is Line Sequential.

   Data Division.
   File Section.
   FD  PayrollFile.
   01  Input-Rec.
       05 Rec-RegionNum Pic X(2).
       05 Rec-RegionName Pic X(15).           
       05 Rec-DeptNum Pic X(5).
       05 Rec-DeptName Pic X(30).           
       05 Rec-EmployeeNum Pic X(5). 
       05 Rec-LastName Pic X(20).
       05 Rec-FirstName Pic X(15).
       05 Rec-Gender Pic X.
       05 Rec-Address Pic X(20).
       05 Rec-CityState Pic X(20).
       05 Rec-Title Pic X(20).
       05 Rec-DOB Pic 9(8).
       05 Rec-DOH.
            10 RecDOH-YYYY Pic 9(4).
            10 RecDOH-MM Pic 9(2).
            10 RecDOH-DD Pic 9(2).
       05 Rec-Marital Pic X.
       05 Rec-Deps Pic 99.
       05 Rec-SD Pic X(3).
       05 Rec-Ins Pic X(3).
       05 Rec-401k Pic V999.
       05 Rec-PayCode Pic X.
       05 Rec-Pay Pic 9(7)V9(2).
       05 Rec-HrsPerWeek Pic 9(2)V9(2).
       05 Rec-CommissionRate Pic V999.
       05 Rec-ActualSales Pic 9(7)V9(2).

   FD  OutputReport.
   01  Output-Rec Pic X(210).

   Working-Storage Section.
   01 WS-EmployeeNum Pic X(5).
   01 WS-DeptName Pic X(30).
   01 WS-Gender Pic X.
       88 ValidGender Values "M" "m" "F" "f".
   01 WS-Marital Pic X.
       88 ValidMarital Values "D" "d" "M" "m" "P" "p" "S" "s" "W"
            "w".
   01 WS-PayCode Pic X.
       88 ValidPayCode Values "C" "c" "H" "h" "S" "s".
   01 WS-HrsPerWeek Pic S9(2)V9(2).
   01  WS-Pay Pic S9(7)V9(2).
   01 WS-DOH.
       10 DOH-YYYY Pic 9(4).
       10 DOH-MM Pic 9(2).
       10 DOH-DD Pic 9(2).
   01 WS-SD Pic X(3).
   01  WS-Date.
       05 WS-YYYY Pic 9(4).
       05 WS-MM Pic 9(2).
       05 WS-DD Pic 9(2).
   01  EndOfFileIndicator Pic X.
       88 EOF Value "Y" When Set To False is "N".
   01  Total-Line.
       05           Pic X(25) Value "Total errors: ".
       05 TL-TotalE  Pic ZZ9.
   01  TotalRE-Line.
       05           Pic X(50) Value "Total record with errors: ".
       05 TL-TotalRE Pic ZZ9.           
   01  TotError Pic 9(3).
   01  TotRecordError Pic 9(3).
   01  CurrentRec Pic X(208).
   01  Blank-Line Pic X Value Spaces.
   01  Report-Fields.
       05 PageNumber Pic 99 Value 0.
       05 LinesPerPage Pic 99 Value 35.
       05 LineNumber Pic 99 Value 99.       

   Procedure Division.
   000-MAIN.
       Perform 100-initialize                     
       Perform until EOF
          Read PayrollFile
             At End 
             Set EOF to True
             not at end
                perform 300-process
          End-read
       End-perform
       Perform 900-finalize
       Close PayrollFile OutputReport
       Stop Run.

   100-initialize. 
       Perform 110-open-files
       Move Zero to TotError
       Move Zero to TotRecordError.

   110-open-files.    
       Open Input PayrollFile
       Open Output OutputReport.


   300-Process.
       Move Input-Rec to CurrentRec
       Move Rec-EmployeeNum to WS-EmployeeNum
       Move Rec-DeptName to WS-DeptName
       Move Rec-Gender to WS-Gender
       Move Rec-Marital to WS-Marital             
       Move Rec-PayCode to WS-PayCode              
       Move Rec-HrsPerWeek to WS-HrsPerWeek
       Move Rec-Pay to WS-Pay
       Move Rec-DOH to WS-DOH
       Perform 400-check.

   400-check.
        If WS-EmployeeNum is Not Numeric
            Add 1 to TotError TotRecordError
        End-If
        If WS-DeptName Is Not Alphabetic
            Add 1 to TotError TotRecordError
        End-If
        If Not ValidGender
            Add 1 to TotError TotRecordError
        End-If
        If Not ValidMarital
            Add 1 to TotError TotRecordError
        End-If
        If Not ValidPayCode
            Add 1 to TotError TotRecordError
        End-If
        If WS-HrsPerWeek Is Negative And >= 60
            Add 2 to TotError
            Add 1 to TotRecordError
        End-If
        If WS-HrsPerWeek Is Negative Or >=60
            Add 1 to TotError TotRecordError
        End-If
        If WS-Pay Is Not Numeric and Is Negative
            Add 2 to TotError
            Add 1 to TotRecordError
        End-If
        If WS-Pay Is Negative Or Not Numeric
            Add 1 to TotError TotRecordError
        End-If
        If Function Test-Date-YYYYMMDD(WS-DOH) Is Not Zero Or WS-DOH Is Not Numeric
            Add 1 to TotError TotRecordError
        End-If.

   900-finalize.
       perform 950-print-grand-total.

   950-print-grand-total.
       Write Output-Rec from Blank-Line
          After advancing 1 line
       Move TotError to TL-TotalE
       Write Output-Rec from Total-Line
          after advancing 1 line
       Move TotRecordError to TL-TotalRE
       Write Output-Rec from TotalRE-Line
          after advancing 1 line.
NicholasC
  • 11
  • 1
  • 2
    See [ask]. Show the errors or messages you get from the compiler. GNU COBOL is a multi-step tool, so we need to see the details. Also, what language level are you targeting? The compiler has `-v[vv]` options you should use, and check out other options while you are there -- you probably want to save intermediate results you can inspect. –  Oct 17 '18 at 17:26
  • Does the existing answer "work" for you? If yes please "accept". If you (or as soon as you) have the privilege to upvote an answer please upvote any answer that you see "useful". And make sure to do the tour... – Simon Sobisch Oct 19 '18 at 18:16

1 Answers1

4

As you've used the GnuCOBOL tag I've just used a simple compile.

Result:

main.cobc: in paragraph '400-check':
main.cobc: 139: error: invalid expression
main.cobc: 143: error: invalid expression
main.cobc: 146: error: invalid expression
main.cobc: 150: error: invalid expression
main.cobc: 153: error: FUNCTION 'TEST-DATE-YYYYMMDD' has invalid parameter
main.cobc: 153: error: invalid expression
main.cobc: 153: error: invalid expression

The invalid expression part is "is negative" (additional line 139 doesn't make sense "Negative And >= 60" as this would never be true; line 146 is even more weird: "Is Not Numeric and Is Negative").

The issue that I am facing now is that the cob file wont compile eventhough it doesn't explicitly show any errors when compiling it

I guess the messages from the compilers are redirected somewhere.

Simon Sobisch
  • 6,263
  • 1
  • 18
  • 38