0

这是我为我的 COBOL 类做的一个示例程序,当我尝试通过命令行编译时,我遇到了一些错误代码的问题。请看下文。COBOL 下面是我的终端代码。如何修复“意外的标识符”?

       IDENTIFICATION DIVISION.
   PROGRAM-ID.      SAMPLE135.
   AUTHOR.          ME.

   ENVIRONMENT DIVISION.


   DATA DIVISION.
   77 FIELD-A PIC 9(2).
   77 FIELD-B PIC 9(2).
   77 FIELD-C PIC 9(3) VALUE ZERO.
   77 FIELD-D PIC 9(3) VALUE ZERO.

   WORKING-STORAGE SECTION.

   PROCEDURE DIVISION.
   FIRST-PARAGRAPH.
       MOVE ZEROS TO FIELD-A FIELD-B.
       PERFORM SECOND-PARAGRAPH.
       PERFORM THIRD-PARAGRAPH.
       PERFORM SECOND-PARAGRAPH.
       PERFORM WRITE-DATA.
       STOP RUN.      

   SECOND-PARAGRAPH.
       ADD 10 TO FIELD-A.
       ADD 20 TO FIELD-B.

   THIRD-PARAGRAPH.
       MULTIPLY FIELD-A BY FIELD-B GIVING FIELD-C.
       DIVIDE FIELD-A INTO FIELD-B GIVING FIELD-D.

   WRITE-DATA.
       DISPLAY FIELD-A.
       DISPLAY FIELD-B.
       DISPLAY FIELD-C.
       DISPLAY FIELD-D.

   END PROGRAM.



Sample2.cbl:9: Error: syntax error, unexpected "Identifier", expecting "end of file"
4

2 回答 2

4

您将“77”数据项放在错误的位置,也缩进。还要确保字段名称从区域 B开始(除非使用自由格式)。尝试

DATA DIVISION.

WORKING-STORAGE SECTION.
   77  FIELD-A          PIC 9(2).
   77  FIELD-B          PIC 9(2).
   77  FIELD-C          PIC 9(3) VALUE ZERO.
   77  FIELD-D          PIC 9(3) VALUE ZERO.

在 Cobol 代码中,通常认为只使用 '.' 会更好。当他们绝对需要时(在程序之前),即

SECOND-PARAGRAPH.
    ADD 10              TO FIELD-A
    ADD 20              TO FIELD-B

    .
THIRD-PARAGRAPH.

最后,这也是我的标准做法缩进TOPIC语句

于 2016-09-16T01:10:02.680 回答
1

WORKING-STORAGE SECTION 标头必须位于 77 级定义之前。

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 FIELD-A PIC 9(2).
       77 FIELD-B PIC 9(2).
       77 FIELD-C PIC 9(3) VALUE ZERO.
       77 FIELD-D PIC 9(3) VALUE ZERO.

您还缺少结束标记中的程序名称。

       END PROGRAM SAMPLE135.
于 2016-09-16T17:23:41.497 回答