2016-09-13 102 views
1

我在cygwin終端中使用OpenCOBOL來編譯該程序,該程序只應從輸入文本文件中讀取並將其打印到格式化的輸出文件中。當我嘗試編譯我得到這個錯誤:COBOL期待文件結尾

programonerjm.cbl:13: Error: syntax error, unexpected "SOURCE-COMPUTER", expecting "end of file" 

我不能完全肯定我procedure division是正確的要麼。

有人能告訴我我做錯了什麼嗎?我知道這可能是一個小錯誤,它讓我發瘋。

 IDENTIFICATION DIVISION. 
     PROGRAM-ID. PROGRAM1. 
     AUTHOR. ME. 
     ********************************************************** 
     * Purpose: Program that outputs an Inventory Report for 
     * Drakea Bike Parts Warehouse. 
     ********************************************************** 
     ENVIRONMENT DIVISION. 

     CONFIGURATION SECTION. 
     SOURCE-COMPUTER. IBM-PC. 
     OBJECT-COMPUTER. IBM-PC. 

     INPUT-OUTPUT SECTION. 

     FILE-CONTROL. 
      SELECT INV-FILE ASSIGN TO 'PR1FA16.txt' 
       ORGANIZATION IS LINE SEQUENTIAL. 
      SELECT OUTPUT-INV-REPORT 
       ASSIGN TO PRINTER 'OUTPUT-INV-REPORT.DAT'. 

     ********************************************************** 

     DATA DIVISION. 

     FILE SECTION. 

     FD INV-FILE. 
     01 INV-RECORD. 
      05 CAT-NUM     PIC X(5). 
      05 ITEM-DESC     PIC X(20). 
      05 UNIT-PURCHASE-PRICE  PIC 999V99. 
      05        PIC X(7). 
      05 QUANTITY-IN-STOCK   PIC 9(3). 
      05 QUANTITY-ON-ORDER   PIC 9(3). 
      05 REORDER-POINT    PIC 9(3). 

     FD OUTPUT-INV-REPORT. 
     01 INVENTORY-REPORT.  
      05        PIC X(80). 

     WORKING-STORAGE SECTION. 
     * EOF FLAG 
     * REPORT SECTION - CREATE HEADERS 

     01 FLAGS-N-SWITCHES. 
      05 EOF-FLAG    PIC X(3)  VALUE 'YES'. 

     01 NUMBER-OF-PAGES   PIC 9(2)  VALUE 1. 

     01 HEADER-LINE-ONE. 
      05 MYDATE    PIC X(10)  VALUE '09/16/2016'. 
      05      PIC X(5)  VALUE SPACES. 
      05 INITIALS    PIC X(3)  VALUE 'RJM'. 
      05      PIC X(10)  VALUE SPACES. 
      05  PIC X(27)  VALUE 'DRAKEA BIKE PARTS WAREHOUSE'. 
      05      PIC X(16)  VALUE SPACES. 
      05 NUM-OF-PAGES   PIC X(7)  VALUE('PAGE 0X'). 
      05      PIC X(2)  VALUE SPACES. 

     01 HEADER-LINE-TWO. 
      05      PIC X(36)  VALUE SPACES. 
      05 NAME-OF-REPORT PIC X(12)  VALUE 'STOCK REPORT'. 
      05      PIC X(32)  VALUE SPACES. 

     01 CATEGORY-HEADER-ONE. 
      05      PIC X(1)  VALUE SPACES. 
      05      PIC X(5)  VALUE 'CAT'. 
      05      PIC X(11)  VALUE SPACES. 
      05      PIC X(4)  VALUE 'ITEM'. 
      05      PIC X(11)  VALUE SPACES. 
      05      PIC X(8)  VALUE 'PURCHASE'. 
      05      PIC X(3)  VALUE SPACES. 
      05      PIC X(8)  VALUE 'QUANTITY'. 
      05      PIC X(4)  VALUE SPACES. 
      05      PIC X(8)  VALUE 'QUANTITY'. 
      05      PIC X(4)  VALUE SPACES. 
      05      PIC X(7)  VALUE 'REORDER'. 
      05      PIC X(8)  VALUE SPACES. 

     01 CATEGORY-HEADER-TWO. 
      05      PIC X(1)  VALUE SPACES. 
      05      PIC X(3)  VALUE 'NUM'. 
      05      PIC X(8)  VALUE SPACES. 
      05      PIC X(11)  VALUE 'DESCRIPTION'. 
      05      PIC X(8)  VALUE SPACES. 
      05      PIC X(5)  VALUE 'PRICE'. 
      05      PIC X(6)  VALUE SPACES. 
      05      PIC X(6)  VALUE 'IN STK'. 
      05      PIC X(5)  VALUE SPACES. 
      05      PIC X(8)  VALUE 'ON ORDER'. 
      05      PIC X(5)  VALUE SPACES. 
      05      PIC X(5)  VALUE 'POINT'. 
      05      PIC X(8)  VALUE SPACES. 

     01 DETAIL-LINE. 
      05 CATALOG-NUM   PIC X(5). 
      05      PIC X(3)  VALUE SPACES. 
      05 ITEM-DESCRIPTION  PIC X(20). 
      05      PIC X(3)  VALUE SPACES. 
      05 PURCHASE-PRICE  PIC $$$$V99. 
      05      PIC X(4)  VALUE SPACES. 
      05 QUANTITY-IN-STK  PIC 99V999. 
      05      PIC X(6)  VALUE SPACES. 
      05 QUANT-ON-ORDER  PIC 99V999. 
      05      PIC X(5)  VALUE SPACES. 
      05 REORDER-PNT   PIC 99V999. 
      05      PIC X(8)  VALUE SPACES. 

     ********************************************************** 

     PROCEDURE DIVISION. 
     100-MAIN-MODULE. 
      PERFORM 110-HOUSEKEEPING. 
      PERFORM 120-READ-FILES. 
      PERFORM 130-PRINT-HEADERS. 
      PERFORM 140-PROCESS-RECORDS. 
      PERFORM 150-PRINT. 
      PERFORM 160-CLOSE-ROUTINE. 
      . 

     110-HOUSEKEEPING. 
      OPEN INPUT  INV-FILE 
        OUTPUT OUTPUT-INV-REPORT 
      . 

     120-READ-FILES. 
      PERFORM UNTIL EOF-FLAG = 'NO' 
        READ INV-FILE 
         AT END 
          MOVE 'NO' TO EOF-FLAG 
         NOT AT END 
          PERFORM 140-PROCESS-RECORDS 
        END-READ 
      END-PERFORM 
      . 

     130-PRINT-HEADERS 
      MOVE NUM-OF-PAGES TO NUM-PAGES 
      MOVE HEADER-LINE-ONE TO INVENTORY-REPORT 
       WRITE INVENTORY-REPORT 
       AFTER ADVANCING 1 LINE 
      MOVE HEADER-LINE-TWO TO INVENTORY-REPORT 
       WRITE INVENTORY-REPORT 
       AFTER ADVANCING 2 LINES 
      MOVE CATEGORY-HEADER-ONE TO INVENTORY-REPORT 
       WRITE INVENTORY-REPORT 
       AFTER ADVANCING 2 LINES 
      MOVE CATEGORY-HEADER-TWO TO INVENTORY-REPORT 
       WRITE INVENTORY-REPORT 
       AFTER ADVANCING 1 LINE. 

     140-PROCESS-RECORDS 
      MOVE CAT-NUM TO CATALOG-NUM 
      MOVE ITEM-DESC TO ITEM-DESCRIPTION 
      MOVE UNIT-PURCHASE-PRICE TO PURCHASE-PRICE 
      MOVE QUANTITY-IN-STOCK TO QUANTITY-IN-STK 
      MOVE QUANTITY-ON-ORDER TO QUANT-ON-ORDER 
      MOVE REORDER-POINT TO REORDER-PNT.   

     150-PRINT 
      MOVE DETAIL-LINE TO INVENTORY-REPORT 
      WRITE INVENTORY-REPORT. 

     160-CLOSE-ROUTINE 
      CLOSE INV-FILE 
        INVENTORY-REPORT 
      STOP RUN. 

這裏是我嘗試讀取文本文件:

X7Y10Gas Tank   12595  010001000100005000750010 
X8Y20Gas Cap    07599  020001000000002500000000 
X6N30Seat    50000  001000000005000200020003 
Y9T40Spark Plugs   02595  002001800200018000800045 
T8N50Helmet    00385  010000000050000000800000 
S9M60Slick 50   05999  000000500020001000000005 
J9M70Gear Box   99999  070500000700000000000100 
K3L80Muffler    35095  100000051000000205000256 
L3D90Water Hose   02995  257000002000000005700300 
M3100Tool Box   25995  078002501500025010000750 
D4110Carborator   05900  000501000050007500250001 
S8120Generator   17700  001000800025001500200015 
+0

您是否有能夠在源數據中顯示「特殊字符」的編輯器(行結束符等)。你可能有一些奇怪的鬆散的。您是使用OpenCOBOL還是更新的GnuCOBOL來處理該錯誤。 –

+0

附加提示:您可能希望在標題後添加一個「WRITE」,並且我假設您要在「NOT AND END」中執行「150-PRINT」(否則您可能並且只有一個書寫的詳細信息行) –

+0

@ user3538149你錯過了什麼,或者你的答案是否適合你?在第二種情況下,請將它標記爲「適合我」這種類型的問題。 –

回答

0

由於錯誤說行13.似乎並不具備相關的程序師什麼。我對開放COBOL並不瞭解,因爲我在COBOL-400上工作過,所以我認爲源計算機和對象計算機都是作爲註釋使用的,因此您應該嘗試讓它們發表評論(通過放*)並嘗試,因爲你不一定要定義它們。請告知是否有幫助。

+1

您被邀請給GnuCOBOL(以前稱爲OpenCOBOL)a請嘗試:-) 「是」:它們被視爲評論,「否」,您不需要將它們明確標記爲評論。 –

3

給出的樣本我得到GnuCOBOL 1.1以下錯誤(至少更新到該版本)在源:

PROGRAM1.cob:58: Error: syntax error, unexpected '(' 

這是指VALUE('PAGE 0X').,我敢肯定你會在一個解決這個問題你自己。

使用GnuCOBOL 2.0 RC-1的編譯器錯誤消息是:

PROGRAM1.cob: 58: error: syntax error, unexpected (
PROGRAM1.cob: in paragraph '100-MAIN-MODULE': 
PROGRAM1.cob: 119: warning: ignoring redundant . 
PROGRAM1.cob: in paragraph '120-READ-FILES': 
PROGRAM1.cob: 137: error: unknown statement '130-PRINT-HEADERS' 

可以忽略「忽略重複」消息,或者修復它(這只是一個警告,因爲這可能點問題 - 但你沒有)。要遵循程序其餘部分的風格(並編寫看起來不像COBOL-74的代碼),我建議刪除100-MAIN-MODULEPERFORM語句後的句點。

行137錯過段落名稱後的一段時間(同樣適用於以下段落名稱,但解析器當前不會從「未知語句」中恢復,因此您只能一個一個地看到它)。

下一個錯誤是:139接下來會發出:

in paragraph '130-PRINT-HEADERS': 
139: error: 'NUM-PAGES' is not defined 
in paragraph '160-CLOSE-ROUTINE': 
167: error: 'INVENTORY-REPORT' is not a file name 

無論是在WORKING-STORAGE或引用重命名VAR(我假設你的意思NUMBER-OF-PAGES)。 CLOSE應該使用文件名(本例中爲OUTPUT-INV-REPORT)而不是記錄名(INVENTORY-REPORT)。

這解決了語法問題。

額外提示:與其

 MOVE HEADER-LINE-ONE TO INVENTORY-REPORT 
      WRITE INVENTORY-REPORT 
      AFTER ADVANCING 1 LINE 

您可以省略附加MOVE(是做在任何情況下內部的,但它只是看起來更好;-),並清楚表明這只是爲WRITE完成:

 WRITE INVENTORY-REPORT 
      FROM HEADER-LINE-ONE 
      AFTER ADVANCING 1 LINE