0

在我的一项课堂作业中,我遇到了有关我的程序部门的错误。这是一个 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.
4

1 回答 1

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

在所有段落中,您都在尝试积累数据并编写摘要行。这不起作用。请参阅上面的执行循环,其中我有“Perform Something To Accumulate your data”,这是您要放置所有代码的段落,这些代码将每个申请人加起来。您需要单独的段落来编写摘要行。

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

  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...
     .

快乐编码:-)

于 2016-06-09T07:04:28.967 回答