我的输出没有显示在 COBOL 中

发布于 2024-09-29 10:43:19 字数 3534 浏览 3 评论 0原文

我的 COBOL 作业再次遇到了一些问题。我认为一切都是它应该的样子,但由于某种原因,当我运行程序时我无法获得任何输出数据。它所做的只是显示空白行,就像有人一遍又一遍地按回车键一样。这真的很糟糕,因为我不知道我是对还是错。这是我的代码:

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

   01 LINE-COUNT                   PIC 99    VALUE ZEROS.

   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(24) VALUE SPACES.
       05                          PIC X(26)
           VALUE 'BASEBALL PLAYER STATISTICS'.
       05                          PIC X(12) 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(6)   VALUE SPACES.
       05  PAGE-1                  PIC X(4)   VALUE 'PAGE'.

   01  HEADING-LINE-2.
       05                          PIC X(6)   VALUE 'LEAGUE'.
       05                          PIC X(3)   VALUE SPACES.
       05                          PIC X(4)   VALUE 'TEAM'.
       05                          PIC X(5)   VALUE SPACES.
       05                          PIC X(4)   VALUE 'NAME'.
       05                          PIC X(10)  VALUE SPACES.
       05                          PIC X(4)   VALUE 'HITS'.
       05                          PIC X(6)   VALUE SPACES.
       05                          PIC X(7)   VALUE 'AT BATS'.
   01  DETAIL-LINE.
       05 BLANK-A-OUT              PIC X      VALUE SPACES.
       05 DL-LEAGUE                PIC XX.
       05 BLANK-B-OUT              PIC X(3)   VALUE SPACES.
       05 DL-TEAM                  PIC X(3).
       05 BLANK-C-OUT              PIC X(3)   VALUE SPACES.
       05 DL-NAME                  PIC X(10).
       05 BLANK-D-OUT              PIC X(3)   VALUE SPACES.
       05 DL-HITS                  PIC ZZ9.
       05 BLANK-E-OUT              PIC X(3)   VALUE SPACES.
       05 DL-AT-BATS               PIC ZZ9.

   PROCEDURE DIVISION.
   100-MAIN.
       OPEN INPUT BASEBALL-FILE-IN
       OPEN OUTPUT BASEBALL-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
       WRITE BASEBALL-RECORD-OUT

       PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
           READ BASEBALL-FILE-IN
               AT END
                   MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
               NOT AT END
                   PERFORM 200-PROCESS-ONE-RECORD
           END-READ
       END-PERFORM

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


   200-PROCESS-ONE-RECORD.
       MOVE LEAGUE-IN TO DL-LEAGUE
       MOVE SPACES TO BLANK-A-OUT
       MOVE TEAM-IN TO DL-TEAM
       MOVE SPACES TO BLANK-B-OUT
       MOVE NAME-IN TO DL-NAME
       MOVE SPACES TO BLANK-C-OUT
       MOVE HITS-IN TO DL-HITS
       MOVE SPACES TO BLANK-D-OUT
       MOVE AT-BATS-IN TO DL-AT-BATS
       MOVE SPACES TO BLANK-E-OUT
       WRITE BASEBALL-RECORD-OUT
           AFTER ADVANCING 2 LINES.

   300-LINE.
       IF  LINE-COUNT >= 50
           PERFORM 400-NEXT-PAGE
       END-IF
       WRITE BASEBALL-RECORD-OUT
           AFTER ADVANCING 1 LINE
       ADD 1 TO LINE-COUNT.

   400-NEXT-PAGE.
       WRITE BASEBALL-RECORD-OUT
           AFTER ADVANCING PAGE
       MOVE ZEROS TO LINE-COUNT.

I am having a bit of a problem with my COBOL homework again. I think everything is how it is suppose to be, but for some reason I cannot get any output data when I run my program. All it does is show blank lines like someone just hit the enter key over and over. It really sucks cause I can't see if I am right or wrong. Here is my code:

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

   01 LINE-COUNT                   PIC 99    VALUE ZEROS.

   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(24) VALUE SPACES.
       05                          PIC X(26)
           VALUE 'BASEBALL PLAYER STATISTICS'.
       05                          PIC X(12) 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(6)   VALUE SPACES.
       05  PAGE-1                  PIC X(4)   VALUE 'PAGE'.

   01  HEADING-LINE-2.
       05                          PIC X(6)   VALUE 'LEAGUE'.
       05                          PIC X(3)   VALUE SPACES.
       05                          PIC X(4)   VALUE 'TEAM'.
       05                          PIC X(5)   VALUE SPACES.
       05                          PIC X(4)   VALUE 'NAME'.
       05                          PIC X(10)  VALUE SPACES.
       05                          PIC X(4)   VALUE 'HITS'.
       05                          PIC X(6)   VALUE SPACES.
       05                          PIC X(7)   VALUE 'AT BATS'.
   01  DETAIL-LINE.
       05 BLANK-A-OUT              PIC X      VALUE SPACES.
       05 DL-LEAGUE                PIC XX.
       05 BLANK-B-OUT              PIC X(3)   VALUE SPACES.
       05 DL-TEAM                  PIC X(3).
       05 BLANK-C-OUT              PIC X(3)   VALUE SPACES.
       05 DL-NAME                  PIC X(10).
       05 BLANK-D-OUT              PIC X(3)   VALUE SPACES.
       05 DL-HITS                  PIC ZZ9.
       05 BLANK-E-OUT              PIC X(3)   VALUE SPACES.
       05 DL-AT-BATS               PIC ZZ9.

   PROCEDURE DIVISION.
   100-MAIN.
       OPEN INPUT BASEBALL-FILE-IN
       OPEN OUTPUT BASEBALL-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
       WRITE BASEBALL-RECORD-OUT

       PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
           READ BASEBALL-FILE-IN
               AT END
                   MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
               NOT AT END
                   PERFORM 200-PROCESS-ONE-RECORD
           END-READ
       END-PERFORM

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


   200-PROCESS-ONE-RECORD.
       MOVE LEAGUE-IN TO DL-LEAGUE
       MOVE SPACES TO BLANK-A-OUT
       MOVE TEAM-IN TO DL-TEAM
       MOVE SPACES TO BLANK-B-OUT
       MOVE NAME-IN TO DL-NAME
       MOVE SPACES TO BLANK-C-OUT
       MOVE HITS-IN TO DL-HITS
       MOVE SPACES TO BLANK-D-OUT
       MOVE AT-BATS-IN TO DL-AT-BATS
       MOVE SPACES TO BLANK-E-OUT
       WRITE BASEBALL-RECORD-OUT
           AFTER ADVANCING 2 LINES.

   300-LINE.
       IF  LINE-COUNT >= 50
           PERFORM 400-NEXT-PAGE
       END-IF
       WRITE BASEBALL-RECORD-OUT
           AFTER ADVANCING 1 LINE
       ADD 1 TO LINE-COUNT.

   400-NEXT-PAGE.
       WRITE BASEBALL-RECORD-OUT
           AFTER ADVANCING PAGE
       MOVE ZEROS TO LINE-COUNT.

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

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

发布评论

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

评论(5

一抹微笑 2024-10-06 10:43:19

编码 COBOL I/O 操作时可以使用几种不同的模式。我看到两个
程序中的独特模式。

模式1:

在FD条目下定义I/O记录布局。您已经为输入文件完成了此操作。
BASEBALL-RECORD-IN 既充当文件 I/O 缓冲区又充当完整记录描述。

模式 2:

定义一个虚拟 FD 记录缓冲区,然后在工作存储下创建其他详细记录定义。
您为输出记录执行了此操作。 BASEBALL-RECORD-OUT 只是一个 I/O 缓冲区
详细记录布局使用三种不同的记录在工作存储下进行保护
布局:HEADING-LINE-1、HEADING-LINE-1 和 DETAIL-LINE。

有什么区别?

主要区别与每条记录何时变得可寻址以及如何读/写数据有关。

使用模式 1 时,仅分配一个记录缓冲区。这是记录
与文件的 FD 子句关联。在您的情况下,这是 36 字节 BASEBALL-RECORD-IN
记录。在与其关联的文件被打开之前,该缓冲区可能无法寻址。尝试
访问此记录缓冲区(通过显式初始化它,将空格移动到它或任何其他引用)将
导致运行时错误(崩溃和烧毁)。打开并READ后,记录中数据可用
与 FD 相关的缓冲区。由于此 FD 具有已定义的记录结构,因此您可以
发出 READ 语句后立即引用其中的任何字段(例如 NAME-IN)。

使用模式 2 时,在工作存储中声明单独的记录结构。这里有记录
HEADING-LINE-1、HEADING-LINE-2 和 DETAIL-LINE 均可寻址
当程序开始运行时 - 即使输出记录缓冲区 BASEBALL-RECORD-OUT(关联
在打开输出文件之前,将无法寻址。这里要记住的事情
是记录缓冲区 BASEBALL-RECORD-OUT 和工作缓冲区之间没有“自动”连接
存储记录 HEADING-LINE-1、HEADING-LINE-2 和 DETAIL-LINE - 您必须显式从工作中移动数据
使用类似以下方式存储到记录缓冲区:

 MOVE HEADING-LINE-1 TO BASEBALL-RECORD-OUT
 WRITE BASEBALL-RECORD-OUT

在每个 WRITE 操作之前。或者,您可以从工作存储记录中写入,如下所示:

 WRITE BASEBALL-RECORD-OUT FROM HEADING-LINE-1

这只是执行上面所示的移动/写入的一种糖衣方式。

这个解释应该让您清楚为什么 READ 将数据直接放入完全
字段记录结构供参考,但 WRITE 需要某种额外的 MOVE。

这是 COBOL 中可用的两种 I/O 模式。当你对这门语言了解得更多时
其他模式也应该浮出水面。

Several different patterns may be used when coding COBOL I/O operations. I see two
distinct patterns in your program.

Pattern 1:

Define I/O record layouts under the FD entry. You have done this for your input file.
BASEBALL-RECORD-IN serves as both a file I/O buffer and a full record description.

Pattern 2:

Define a dummy FD record buffer then create additional detail record definitions under Working Storage.
You did this for your output record. BASEBALL-RECORD-OUT is just an I/O buffer and
the detail record layouts are defend under Working Strorage using three different record
layouts: HEADING-LINE-1, HEADING-LINE-1 and DETAIL-LINE.

What is the difference?

The primary differences relate to when each of these records becomes addressable and how you read/write data.

When using Pattern 1, only a single record buffer is allocated. This is the record
associated with the file's FD clause. In your case this is the 36 byte BASEBALL-RECORD-IN
record. This buffer may not be addressable until after the file it is associated with has been OPENed. Attempting
to access this record buffer (by explicitly initializing it, moving spaces to it or any other reference) would
cause a run-time error (crash and burn). After the open and READ, data are available in the record
buffer associated with the FD. Since this FD has a defined record structure, you may
reference any of the fields in it (e.g. NAME-IN) immediately after issuing a READ statement.

When using Pattern 2, Separate record structures are declared in Working Storage. Here the records
HEADING-LINE-1, HEADING-LINE-2 and DETAIL-LINE are all addressable
when the program starts running - even though the output record buffer BASEBALL-RECORD-OUT (associated
with the FD) will not be addressable until after the output file has been opened. The thing to remember here
is that there is no "automatic" connection between the record buffer BASEBALL-RECORD-OUT and the Working
storage records HEADING-LINE-1, HEADING-LINE-2 and DETAIL-LINE - you have to explicitly MOVE the data from Working
Storage to the record buffer using something like:

 MOVE HEADING-LINE-1 TO BASEBALL-RECORD-OUT
 WRITE BASEBALL-RECORD-OUT

before each and every WRITE operation. Alternatively you could write from the Working Storage record as in:

 WRITE BASEBALL-RECORD-OUT FROM HEADING-LINE-1

This is just a sugar coated way of doing the MOVE/WRITE illustrated above.

This explanation should make it clear to you why the READ puts data directly into a fully
fielded record structure for reference, but WRITE requires an additional MOVE of some sort.

These are two I/O patterns available in COBOL. As you learn more about the language quite a few
additional patterns should come to light as well.

女中豪杰 2024-10-06 10:43:19

您永远不会将从 BASEBALL-2.SEQ 读取的数据移动到用于写入 BASEBALL-2.RPT 的记录中。

你可以做类似的事情

* WRITE THE HEADER INFO
MOVE HEADING-LINE-1 TO BASEBALL-RECORD-OUT 
WRITE BASEBALL-RECORD-OUT 

或者

WRITE BASEBALL-RECORD-OUT FROM HEADING-LINE-1

类似地你可以写细节行

* WRITE THE DETAIL
MOVE DETAIL-LINE TO BASEBALL-RECORD-OUT 
WRITE BASEBALL-RECORD-OUT 

You are never moving the data you read from BASEBALL-2.SEQ into the record used to write BASEBALL-2.RPT.

You can do something like

* WRITE THE HEADER INFO
MOVE HEADING-LINE-1 TO BASEBALL-RECORD-OUT 
WRITE BASEBALL-RECORD-OUT 

Or

WRITE BASEBALL-RECORD-OUT FROM HEADING-LINE-1

Similarly you can write the details line

* WRITE THE DETAIL
MOVE DETAIL-LINE TO BASEBALL-RECORD-OUT 
WRITE BASEBALL-RECORD-OUT 
佼人 2024-10-06 10:43:19

自从我接触 Cobol 以来已经有一段时间了,但您可能错过了更新 BASEBALL-RECORD-OUT。

It's been a while since I touched Cobol but you are probably missing updating BASEBALL-RECORD-OUT.

知足的幸福 2024-10-06 10:43:19

在写入 BASEBALL-RECORD-OUT 之前,必须将 HEADING-LINE-1、HEADING-LINE-2 和 DETAIL-LINE 移动到 BASEBALL-RECORD-OUT。

You have to move HEADING-LINE-1, HEADING-LINE-2, and DETAIL-LINE to BASEBALL-RECORD-OUT before you WRITE BASEBALL-RECORD-OUT.

忆离笙 2024-10-06 10:43:19

我看到从 300- 和 400- 开始的代码中有两段没有执行,因为它们没有执行并且低于停止运行。对于输出到文件,可能会省略 io-control 条目,并且输出似乎被写入文件而不是显示屏或打印机。这将取决于任何默认设置或任何外部分配或重定向的设置。

I see there are two paragraphs which are not executed in the code starting 300- and 400- as they are not performed and are below the stop run. There may be i-o-control entries omitted for the output to the file and the output appears to be written to a file and not to a display screen or printer. This would depend any default settings or those of any external assignments or redirects.

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