出现和下标

发布于 2024-10-14 23:45:37 字数 3851 浏览 4 评论 0原文

我似乎在处理 COBOL 时遇到了另一个问题。我的老师分配给我们一个任务,就是将姓名文件分成两列,向下 54 行。我认为这会很简单,就像我在书中看到的那样,因为它或多或少使用一个新函数来完成我已经准备好的事情,但是当我回到家并放下我的代码时,一切都变得很糟糕。我编写的程序,出于某种我不知道的原因,只在第一行的第一列中写入一个名称,并且在 54 行中执行相同的操作。我显然走错了路,但在我看来,它看起来是对的。这就是我得到的:

   WORKING-STORAGE SECTION.
   01  ARE-THERE-MORE-RECORDS              PIC X(3)  VALUE 'YES'.

   01  REPORT-START                        PIC X     VALUE 'Y'.

   01  LINE-COUNT                          PIC 99    VALUE ZEROS.

   01  PAGE-NUMBER                         PIC 99    VALUE ZEROS.

   01  NAME-COUNT                          PIC 9(3)  VALUE ZEROS.

   01  WORK-AREA-1.
       05  N-COLUMN-1                      PIC 99    VALUE ZEROS.

   01  WORK-AREA-2.
       05  N-COLUMN-2                      PIC 9(3)  VALUE 54.

   01  NAME-STORAGE.
       05  NAME-STO    OCCURS 108 TIMES    PIC X(30).

   01  WS-DATE.
       05  RUN-YEAR                        PIC XX.
       05  RUN-MONTH                       PIC XX.
       05  RUN-DAY                         PIC XX.

   01  HEADING-LINE-1.
       05                                  PIC X(32) VALUE SPACES.
       05                                  PIC X(16)
           VALUE 'NAME LIST REPORT'.
       05                                  PIC X(6)  VALUE SPACES.
       05  HL-1-DATE.
           10  MONTH-2                     PIC XX.
           10                              PIC X      VALUE '/'.
           10  DAY-2                       PIC XX.
           10                              PIC X      VALUE '/'.
           10  YEAR-2                      PIC XX.
       05                                  PIC X(4)   VALUE SPACES.
       05  PAGE-1                          PIC X(4)   VALUE 'PAGE'.
       05                                  PIC X(1)   VALUE SPACES.
       05  NUMBER-PAGE                     PIC Z9.

   01  DETAIL-LINE.
       05 BLANK-A-OUT                      PIC X(4)   VALUE SPACES.
       05 DL-COLUMN-1                      PIC X(30).
       05 BLANK-E-OUT                      PIC X(20)  VALUE SPACES.
       05 DL-COLUMN-2                      PIC X(30).

   PROCEDURE DIVISION.
   100-MAIN.
       OPEN INPUT NAMELIST-FILE-IN
       OPEN OUTPUT NAMELIST-FILE-OUT

       ACCEPT WS-DATE FROM DATE
       MOVE RUN-MONTH TO MONTH-2
       MOVE RUN-DAY TO DAY-2
       MOVE RUN-YEAR TO YEAR-2

       PERFORM 200-NEXT-PAGE

       PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
           READ NAMELIST-FILE-IN
               AT END
                   MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
               NOT AT END
                   PERFORM 300-STORE-NAME
           END-READ
       END-PERFORM

       CLOSE NAMELIST-FILE-IN
       CLOSE NAMELIST-FILE-OUT
       STOP RUN.

   200-NEXT-PAGE.
       ADD 1 TO PAGE-NUMBER
       MOVE PAGE-NUMBER TO NUMBER-PAGE
       MOVE HEADING-LINE-1 TO NAMELIST-RECORD-OUT
       IF REPORT-START = 'N'
           WRITE NAMELIST-RECORD-OUT
               AFTER ADVANCING PAGE
       ELSE
           MOVE 'N' TO REPORT-START
           WRITE NAMELIST-RECORD-OUT
               AFTER ADVANCING 1 LINE
       END-IF.
       MOVE ZEROS TO LINE-COUNT.

   300-STORE-NAME.
       ADD 1 TO NAME-COUNT
       MOVE NAME-IN TO NAME-STORAGE
       IF NAME-COUNT > 54
           PERFORM 400-PROCESS-FILE
       END-IF.

   400-PROCESS-FILE.
       IF  LINE-COUNT >= 52
           PERFORM 200-NEXT-PAGE
       END-IF
       ADD 1 TO LINE-COUNT
       ADD 1 TO N-COLUMN-1
       ADD 1 TO N-COLUMN-2
       MOVE NAME-STO (N-COLUMN-1) TO DL-COLUMN-1
       MOVE NAME-STO (N-COLUMN-2) TO DL-COLUMN-2
       MOVE DETAIL-LINE TO NAMELIST-RECORD-OUT
       WRITE NAMELIST-RECORD-OUT
           AFTER ADVANCING 1 LINE
       IF N-COLUMN-2 = 108
           MOVE 0 TO NAME-COUNT
           MOVE 0 TO N-COLUMN-1
           MOVE 54 TO N-COLUMN-2
       END-IF.

这不是我要做的全部,但在我弄清楚这一点之前我无法继续。

I seem to have yet another problem dealing with COBOL. My teacher has assigned us with having to take a file of names and make it into two columns going 54 rows down. I thought this was going to be simple as I looked in the book as it was more or less using a new function to do what I had all ready been doing, but once I got home and put down my code it all went to heck. Th program I made, for some reason unknown to me, only writes one name in the first column of row one and the does the same ever 54 rows. I am obviously on the wrong track but in my mind it looks right. Here is what I got:

   WORKING-STORAGE SECTION.
   01  ARE-THERE-MORE-RECORDS              PIC X(3)  VALUE 'YES'.

   01  REPORT-START                        PIC X     VALUE 'Y'.

   01  LINE-COUNT                          PIC 99    VALUE ZEROS.

   01  PAGE-NUMBER                         PIC 99    VALUE ZEROS.

   01  NAME-COUNT                          PIC 9(3)  VALUE ZEROS.

   01  WORK-AREA-1.
       05  N-COLUMN-1                      PIC 99    VALUE ZEROS.

   01  WORK-AREA-2.
       05  N-COLUMN-2                      PIC 9(3)  VALUE 54.

   01  NAME-STORAGE.
       05  NAME-STO    OCCURS 108 TIMES    PIC X(30).

   01  WS-DATE.
       05  RUN-YEAR                        PIC XX.
       05  RUN-MONTH                       PIC XX.
       05  RUN-DAY                         PIC XX.

   01  HEADING-LINE-1.
       05                                  PIC X(32) VALUE SPACES.
       05                                  PIC X(16)
           VALUE 'NAME LIST REPORT'.
       05                                  PIC X(6)  VALUE SPACES.
       05  HL-1-DATE.
           10  MONTH-2                     PIC XX.
           10                              PIC X      VALUE '/'.
           10  DAY-2                       PIC XX.
           10                              PIC X      VALUE '/'.
           10  YEAR-2                      PIC XX.
       05                                  PIC X(4)   VALUE SPACES.
       05  PAGE-1                          PIC X(4)   VALUE 'PAGE'.
       05                                  PIC X(1)   VALUE SPACES.
       05  NUMBER-PAGE                     PIC Z9.

   01  DETAIL-LINE.
       05 BLANK-A-OUT                      PIC X(4)   VALUE SPACES.
       05 DL-COLUMN-1                      PIC X(30).
       05 BLANK-E-OUT                      PIC X(20)  VALUE SPACES.
       05 DL-COLUMN-2                      PIC X(30).

   PROCEDURE DIVISION.
   100-MAIN.
       OPEN INPUT NAMELIST-FILE-IN
       OPEN OUTPUT NAMELIST-FILE-OUT

       ACCEPT WS-DATE FROM DATE
       MOVE RUN-MONTH TO MONTH-2
       MOVE RUN-DAY TO DAY-2
       MOVE RUN-YEAR TO YEAR-2

       PERFORM 200-NEXT-PAGE

       PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
           READ NAMELIST-FILE-IN
               AT END
                   MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
               NOT AT END
                   PERFORM 300-STORE-NAME
           END-READ
       END-PERFORM

       CLOSE NAMELIST-FILE-IN
       CLOSE NAMELIST-FILE-OUT
       STOP RUN.

   200-NEXT-PAGE.
       ADD 1 TO PAGE-NUMBER
       MOVE PAGE-NUMBER TO NUMBER-PAGE
       MOVE HEADING-LINE-1 TO NAMELIST-RECORD-OUT
       IF REPORT-START = 'N'
           WRITE NAMELIST-RECORD-OUT
               AFTER ADVANCING PAGE
       ELSE
           MOVE 'N' TO REPORT-START
           WRITE NAMELIST-RECORD-OUT
               AFTER ADVANCING 1 LINE
       END-IF.
       MOVE ZEROS TO LINE-COUNT.

   300-STORE-NAME.
       ADD 1 TO NAME-COUNT
       MOVE NAME-IN TO NAME-STORAGE
       IF NAME-COUNT > 54
           PERFORM 400-PROCESS-FILE
       END-IF.

   400-PROCESS-FILE.
       IF  LINE-COUNT >= 52
           PERFORM 200-NEXT-PAGE
       END-IF
       ADD 1 TO LINE-COUNT
       ADD 1 TO N-COLUMN-1
       ADD 1 TO N-COLUMN-2
       MOVE NAME-STO (N-COLUMN-1) TO DL-COLUMN-1
       MOVE NAME-STO (N-COLUMN-2) TO DL-COLUMN-2
       MOVE DETAIL-LINE TO NAMELIST-RECORD-OUT
       WRITE NAMELIST-RECORD-OUT
           AFTER ADVANCING 1 LINE
       IF N-COLUMN-2 = 108
           MOVE 0 TO NAME-COUNT
           MOVE 0 TO N-COLUMN-1
           MOVE 54 TO N-COLUMN-2
       END-IF.

This is not all I have to do, but until I figure this out I cannot continue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

远昼 2024-10-21 23:45:37

我不熟悉 COBOL 的这种方言,但我认为问题在于:

MOVE NAME-IN TO NAME-STORAGE

我应该看起来像这样:

MOVE NAME-IN TO NAME-STO OF NAME-STORAGE(NAME-COUNT)

我是对是错还是我只是在做梦?

I'm not familiar with this dialect of COBOL, but i thnk the problem is with:

MOVE NAME-IN TO NAME-STORAGE

I t should look like this:

MOVE NAME-IN TO NAME-STO OF NAME-STORAGE(NAME-COUNT)

Am i right am i wrong or am i just dreaming?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文