编译器认为我指的是不存在的段落或部分

时间:2016-03-24 19:08:59

标签: cobol gnucobol cobol85 cobol.net procobol

我在课堂上的任务中遇到了关于我的程序分工的错误。这是一个COBOL计划,应该保持申请人的平均身高和体重,棕色眼睛的申请人数,男性申请人数和女性申请人数的总计。此程序还应打印满足特定要求的申请人的信息,但我几乎所有的执行陈述都会出错

  

COBCH0034操作数操作数应为数字   在此上下文中需要一个数值,并且您已指定了非数字值。

     

COBCH0014操作数无效   您指定的操作数在某种程度上是不正确的,并且您的COBOL系统无法处理。例如,您可能指定了一个负整数,其中只允许正整数

       identification division.
   program-id. ELECTRA-MODELING-AGENCY.
  ******************************************************************
  *THIS PROGRAM PRODUCES THE REPORT ACCORDING TO THE GIVEN PRINTER 
  *SPACING CHART                                                   *
  ******************************************************************
   environment division.
   INPUT-OUTPUT SECTION.
   FILE-CONTROL.
   SELECT INPUT-FILE ASSIGN TO "INFILE.txt"
          Organization is line sequential.
   SELECT OUTPUT-FILE ASSIGN TO "CHOSEN-APLICANTS.TXT"
          Organization is line sequential.
   data division.
   FILE SECTION.
   FD INPUT-FILE.
   01 INPUT-REC.
       05 APPLICANTS-NAME              PIC X(20).
       05 APPLICANTS-WEIGHT            PIC 9(3).
       05 APPLICANTS-HEIGHT            PIC 9(2).
       05 APPLICANTS-EYE-CODE          PIC X.
       05 APPLICANTS-HAIR-CODE         PIC X.
       05 APPLICANTS-GENDER            PIC X.
   FD OUTPUT-FILE.
   01 OUTPUT-REC PIC X(78).
   WORKING-STORAGE SECTION.
   01 EOF PIC X VALUE "N".
   01 HEADING-1.
       05 FILLER                       PIC X(41) VALUE "M"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(2) VALUE "O"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(2) VALUE "D" 
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(2) VALUE "E"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(2) VALUE "L"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(3) VALUE "R"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(2) VALUE "E"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(2) VALUE "P"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(2) VALUE "O"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(2) VALUE "R"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(2) VALUE "T"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(16) VALUE SPACES.
   01 HEADING-2.
       05 FILLER                       PIC X(23) VALUE "NAME"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(13) VALUE "SEX"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(10) VALUE "WEIGHT"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(8) VALUE "HEIGHT"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(5) VALUE "EYE"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(6) VALUE "COLOR"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(6) VALUE "HAIR"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(6) VALUE "COLOR"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X VALUE SPACES.
   01 DETAIL-LINE.
       05 FILLER                       PIC X(10) VALUE SPACES.
       05 NAME-OUT                     PIC X(20).
       05 FILLER                       PIC X(4) VALUE SPACES.
       05 GENDER-OUT                   PIC X.
       05 FILLER                       PIC X(6) VALUE SPACES.
       05 WEIGHT-OUT                   PIC X(3).
       05 FILLER                       PIC X(6) VALUE SPACES.
       05 HEIGHT-OUT                   PIC XX.
       05 FILLER                       PIC X(6) VALUE SPACES.
       05 EYE-COLOR-OUT                PIC X(5). 
       05 FILLER                       PIC X(6) VALUE SPACES.
       05 HAIR-COLOR-OUT               PIC X(6).
   01 SUMMARY-LINE-01
       05 FILLER                       PIC X(17) VALUE "AVERAGE"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(7) VALUE "HEIGHT"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(3) VALUE "OF"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(4) VALUE "ALL"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(12) VALUE "APPLICANTS:"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X.
       05 AVERAGE-HEIGHT               PIC ZZZ9.
       05 FILLER                       PIC X(12) VALUE SPACES.
   01 SUMMARY-LINE-02
       05 FILLER                       PIC X(17) VALUE "AVERAGE"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(7) VALUE "WEIGHT"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(3) VALUE "OF"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(4) VALUE "ALL"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(12) VALUE "APPLICANTS:"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X.
       05 AVERAGE-WEIGHT               PIC ZZZ9.
       05 FILLER                       PIC X(12) VALUE SPACES.
   01 SUMMARY-LINE-03
       05 FILLER                       PIC X(16) VALUE "NUMBER"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(3) VALUE "OF"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(11) VALUE "BROWN-EYED"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(12) VALUE "APPLICANTS:"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC XX.
       05 BROWN-EYED-APPLICANTS        PIC ZZZ9.
       05 FILLER                       PIC X(12) VALUE SPACES.
   01 SUMMARY-LINE-04
       05 FILLER                       PIC X(16) VALUE "NUMBER"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(3) VALUE "OF"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(5) VALUE "MALE"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(12) VALUE "APPLICANTS:"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(8) VALUE SPACES.
       05 MALE-APPLICANTS              PIC ZZZ9.
       05 FILLER                       PIC X(12) VALUE SPACES.
   01 SUMMARY-LINE-05
       05 FILLER                       PIC X(16) VALUE "NUMBER"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(3) VALUE "OF"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(7) VALUE "FEMALE"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(11) VALUE "APPLICANTS:"
       JUSTIFIED RIGHT.
       05 FILLER                       PIC X(6) VALUE SPACES.
       05 FEMALE-APPLICANTS            PIC ZZZ9.
       05 FILLER                       PIC X(12) VALUE SPACES.
   procedure division.
   100-main.
       OPEN INPUT INPUT-FILE
            OUTPUT OUTPUT-FILE
       PERFORM UNTIL EOF = 'Y'
           READ INPUT-FILE
           AT END MOVE 'Y' TO EOF
           NOT AT END
      PERFORM 200-HEADING.
      PERFORM 200-AVG-HEIGHT.
      PERFORM 200-AVG-WEIGHT.
      PERFORM 200-BROWN-EYED-APPS.
      PERFORM 200-MALE-APPS.
      PERFORM 200-FEMALE-APPS.
      PERFORM 200-MALE-DETAIL-LINE.
      PERFORM 200-FEMALE-DETAIL-LINE.
   CLOSE INPUT-FILE, OUTPUT-FILE.
   STOP RUN.
   200-HEADING.
        WRITE OUTPUT-REC FROM HEADING-1.
           MOVE SPACES TO OUTPUT-REC.
           WRITE OUTPUT-REC.
           WRITE OUTPUT-REC FROM HEADING-2.
           MOVE SPACES TO OUTPUT-REC.
           WRITE OUTPUT-REC.
   200-AVG-HEIGHT.
          IF NOT AT END
          ADD APPLICANTS-HEIGHT TO AVERAGE-HEIGHT
          ELSE AT END
          DIVIDE AVERAGE-HEIGHT BY 21.
          WRITE OUTPUT-REC FROM SUMMARY-LINE-01.
   200-AVG-WEIGHT.
          IF NOT AT END
          ADD APPLICANTS-WEIGHT TO AVERAGE-WEIGHT
          ELSE AT END
          DIVIDE AVERAGE-HEIGHT BY 21.
          WRITE OUTPUT-REC FROM SUMMARY-LINE-02.
   200-BROWN-EYED-APPS.
          IF  APPLICANTS-EYE-CODE = 2
          ADD 1 TO BROWN-EYED-APPLICANTS
          ELSE CONTINUE.
          WRITE OUTPUT-REC FROM SUMMARY-LINE-03.
   200-MALE-APPS.
           IF APPLICANTS-GENDER = M
           ADD 1 TO MALE-APPLICANTS
           ELSE CONTINUE.
           WRITE OUTPUT-REC FROM SUMMARY-LINE-04.
   200-FEMALE-APPS.
           IF APPLICANTS-GENDER = F
           ADD 1 TO FEMALE-APPLICANTS
           ELSE CONTINUE.
           WRITE OUTPUT-REC FROM SUMMARY-LINE-05.
   200-MALE-DETAIL-LINE.
           IF APPLICANTS-HAIR-CODE = 1
           IF APPLICANTS-EYE-CODE = 1
           IF APPLICANTS-GENDER = M
           IF APPLICANTS-HEIGHT >= 72
           IF 185 <= APPLICANTS-WEIGHT <= 200
           ELSE CONTINUE.
           WRITE OUTPUT-REC FROM 01 DETAIL-LINE.
   200-FEMALE-DETAIL-LINE.
           IF APPLICANTS-HAIR-CODE = 2
           IF APPLICANTS-EYE-CODE = 2
           IF APPLICANTS-GENDER = F
           IF 62 <= APPLICANTS-HEIGHT <= 64
           IF 110 <= APPLICANTS-WEIGHT <= 125
           ELSE CONTINUE.
           WRITE OUTPUT-REC FROM 01 DETAIL-LINE.

   end program ELECTRA-MODELING-AGENCY.

1 个答案:

答案 0 :(得分:1)

所以你有几件事情在这里出错了。让我详细介绍其中的一些,并给你一些解决方法。

你正在使用句点来结束语句,当你将它与一些较新的语句(以及更新的,我的意思只有30岁)的语句混合时,这很糟糕和糟糕,比如内联执行和读/结束/不是在结束/结束阅读。

而不是:

  PERFORM UNTIL EOF = 'Y'
      READ INPUT-FILE
      AT END MOVE 'Y' TO EOF
      NOT AT END
  PERFORM 200-HEADING.
  PERFORM 200-AVG-HEIGHT.
  PERFORM 200-AVG-WEIGHT.
  PERFORM 200-BROWN-EYED-APPS.
  PERFORM 200-MALE-APPS.
  PERFORM 200-FEMALE-APPS.
  PERFORM 200-MALE-DETAIL-LINE.
  PERFORM 200-FEMALE-DETAIL-LINE.
  CLOSE INPUT-FILE, OUTPUT-FILE.
  STOP RUN.

你需要这样的东西:

  PERFORM UNTIL EOF = 'Y'    <--- This is better as an 88 level
      READ INPUT-FILE
         AT END MOVE 'Y' TO EOF
         NOT AT END
           PERFORM SOMETHING <--- You need to accumulate you data here
      END-READ
  END-PERFORM

  PERFORM 200-HEADING
  PERFORM 200-AVG-HEIGHT
  PERFORM 200-AVG-WEIGHT
  PERFORM 200-BROWN-EYED-APPS
  PERFORM 200-MALE-APPS
  PERFORM 200-FEMALE-APPS
  PERFORM 200-MALE-DETAIL-LINE
  PERFORM 200-FEMALE-DETAIL-LINE
  CLOSE INPUT-FILE, OUTPUT-FILE
  STOP RUN.                   <--- This is the only period you need
                              <--- In your mainline

你不能这样做:

  200-AVG-HEIGHT.
      IF NOT AT END            <--- NOT AT END and AT END only work
                               <--- in the context of a READ statement
      ADD APPLICANTS-HEIGHT TO AVERAGE-HEIGHT
      ELSE AT END
      DIVIDE AVERAGE-HEIGHT BY 21.
      WRITE OUTPUT-REC FROM SUMMARY-LINE-01.

在循环浏览文件时,通过将每个申请人添加到APPLICANTS-HEIGHT并将1添加到您的APPLICANTS-COUNT来累积总高度。当您准备好对高度进行汇总时,请执行以下操作:

  200-AVG-HEIGHT.
      DIVIDE APPLICANTS-HEIGHT BY APPLICANTS-COUNT
      WRITE OUTPUT-REC FROM SUMMARY-LINE-01
      .       <---- Again, you only need a single period to end a paragraph

在所有段落中,您都在尝试累积数据并编写摘要行。这不起作用。请参阅上面的执行循环,其中包含“执行某些内容以累积您的数据”,这是您希望将所有代码添加到每个申请人的段落。您需要单独的段落来编写摘要行。

所以这应该发生在每一条记录上:

  200-MALE-DETAIL-LINE.
       IF APPLICANTS-HAIR-CODE = 1
       IF APPLICANTS-EYE-CODE = 1
       IF APPLICANTS-GENDER = M
       IF APPLICANTS-HEIGHT >= 72
       IF 185 <= APPLICANTS-WEIGHT <= 200
       ELSE CONTINUE.   <--- you are doing nothing here
       WRITE OUTPUT-REC FROM 01 DETAIL-LINE.

最好这样写:

  200-MALE-DETAIL-LINE.
       IF APPLICANTS-HAIR-CODE = 1
         AND APPLICANTS-EYE-CODE = 1
           AND APPLICANTS-GENDER = M
             AND APPLICANTS-HEIGHT >= 72
               AND (185 <= APPLICANTS-WEIGHT <= 200)
          WRITE OUTPUT-REC FROM 01-DETAIL-LINE
       END-IF

这应该让你去。您需要将这些提示应用于所有其他段落。简而言之,您的程序通常应如下所示:

  Open Files
  Perform until EOF
    Read a-record
      not at end
        Perform Do-Detail-Lines
      at end
        Set EOF to true
    End-Read
  End-Perform

  Perform Do-Summary-Lines

  Close files
  Stop Run.

  Do-Detail-Lines.
     ...add up all the things you are averaging and counting...
     ...populate detail line...   
     write output-rec from detail-line
     .

  Do-Summary-Lines.
     ...calculate all averages...
     ...populate summary line...
     write output-red from summary-line
     ...repeat as needed for other summary-lines...
     .

快乐编码: - )