gpt4 book ai didi

cobol - 如何纠正 COBOL 程序 SYSOUT 假脱机中打印输出时的逻辑错误?

转载 作者:行者123 更新时间:2023-12-02 02:37:49 29 4
gpt4 key购买 nike

这是cobol代码

     *-----------------------
IDENTIFICATION DIVISION.
*-----------------------
PROGRAM-ID. TOPACCTS
AUTHOR. Otto B. Boolean.
*--------------------
ENVIRONMENT DIVISION.
*--------------------
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT PRINT-LINE ASSIGN TO PRTLINE.
SELECT CUST-RECS ASSIGN TO CUSTRECS.
*-------------
DATA DIVISION.
*-------------
FILE SECTION.
FD PRINT-LINE RECORDING MODE F.
01 PRINT-REC.
05 FILLER PIC X(02) VALUE SPACES.
05 LAST-NAME-O PIC X(25).
05 FILLER PIC X(02) VALUE SPACES.
05 ACCT-BALANCE-O PIC X(18).
05 FILLER PIC X(33) VALUE SPACES.
*
FD CUST-RECS RECORDING MODE F.
01 CUSTOMER-REC.
05 LAST-NAME PIC X(25).
05 FILLER PIC X(10) VALUE SPACES.
05 FIRST-NAME PIC X(15).
05 FILLER PIC X(10) VALUE SPACES.
05 ACCT-BALANCE PIC X(18).
05 FILLER PIC X(02) VALUE SPACES.


*
WORKING-STORAGE SECTION.
01 Filler.
05 LASTREC PIC X VALUE SPACE.
05 TOTL PIC 9(2) VALUE ZEROS.
05 SUB1 PIC 9(2) VALUE 01.
05 S PIC X(12) VALUE "8,500,000.00".

*
01 OVERLIMIT.
03 FILLER OCCURS 20 TIMES.
05 OL-ACCT-NO PIC X(8).
05 OL-ACCT-LIMIT PIC S9(7)V99 COMP-3.
05 OL-ACCT-BALANCE PIC S9(7)V99 COMP-3.
05 OL-LASTNAME PIC X(20).
05 OL-FIRSTNAME PIC X(15).
*
01 HEADER-1.
05 FILLER PIC X(20)
VALUE 'Financial Report for'.
05 FILLER PIC X(01) VALUE SPACES.
05 FILLER PIC X(14)
VALUE "Account holder".
05 FILLER PIC X(45) VALUE SPACES.
*
01 HEADER-2.
05 FILLER PIC X(05) VALUE 'Year '.
05 HDR-YR PIC 9(04).
05 FILLER PIC X(02) VALUE SPACES.
05 FILLER PIC X(06) VALUE 'Month '.
05 HDR-MO PIC X(02).
05 FILLER PIC X(02) VALUE SPACES.
05 FILLER PIC X(04) VALUE 'Day '.
05 HDR-DAY PIC X(02).
05 FILLER PIC X(56) VALUE SPACES.
*
01 HEADER-3.
05 FILLER PIC X(08) VALUE 'No.'.
05 FILLER PIC X(02) VALUE SPACES.
05 FILLER PIC X(10) VALUE 'Cust Name '.
05 FILLER PIC X(15) VALUE SPACES.
05 FILLER PIC X(08) VALUE 'Balance '.
05 FILLER PIC X(40) VALUE SPACES.
*
01 HEADER-4.
05 FILLER PIC X(08) VALUE '--------'.
05 FILLER PIC X(02) VALUE SPACES.
05 FILLER PIC X(10) VALUE '----------'.
05 FILLER PIC X(15) VALUE SPACES.
05 FILLER PIC X(10) VALUE '----------'.
05 FILLER PIC X(02) VALUE SPACES.
05 FILLER PIC X(13) VALUE '-------------'.
05 FILLER PIC X(40) VALUE SPACES.
*
01 WS-CURRENT-DATE-DATA.
05 WS-CURRENT-DATE.
10 WS-CURRENT-YEAR PIC 9(04).
10 WS-CURRENT-MONTH PIC 9(02).
10 WS-CURRENT-DAY PIC 9(02).
05 WS-CURRENT-TIME.
10 WS-CURRENT-HOURS PIC 9(02).
10 WS-CURRENT-MINUTE PIC 9(02).
10 WS-CURRENT-SECOND PIC 9(02).
10 WS-CURRENT-MILLISECONDS PIC 9(02).
*
*------------------
PROCEDURE DIVISION.
*------------------
OPEN-FILES.
OPEN INPUT CUST-RECS.
OPEN OUTPUT PRINT-LINE.
DISPLAY HEADER-1.
PERFORM WRITE-HEADERS.
DISPLAY 'PREPARED ON ' HDR-DAY '.' HDR-MO '.' HDR-YR.
DISPLAY '# OF RECORDS: ' TOTL.
DISPLAY '==========================================='.
PERFORM READ-NEXT-RECORD.


*
WRITE-HEADERS.
MOVE FUNCTION CURRENT-DATE TO WS-CURRENT-DATE-DATA.
MOVE WS-CURRENT-YEAR TO HDR-YR.
MOVE WS-CURRENT-MONTH TO HDR-MO.
MOVE WS-CURRENT-DAY TO HDR-DAY.
MOVE SPACES TO PRINT-REC.
WRITE PRINT-REC AFTER ADVANCING 1 LINES.
MOVE SPACES TO PRINT-REC.
*
*
READ-NEXT-RECORD.
PERFORM READ-RECORD
PERFORM UNTIL LASTREC = 'Y'
PERFORM THE-RICH
PERFORM WRITE-RECORD
PERFORM READ-RECORD
END-PERFORM.
EXIT.
*

*
READ-RECORD.
READ CUST-RECS
AT END MOVE 'Y' TO LASTREC
END-READ.
EXIT.
*
THE-RICH.
IF FUNCTION NUMVAL-C(S) < FUNCTION NUMVAL-C(ACCT-BALANCE)
THEN
DISPLAY LAST-NAME ACCT-BALANCE
MOVE ACCT-BALANCE TO ACCT-BALANCE-O
MOVE LAST-NAME TO LAST-NAME-O
ADD 1 TO SUB1
MOVE SUB1 TO TOTL
END-IF.
EXIT.

*
WRITE-RECORD.
MOVE ACCT-BALANCE TO ACCT-BALANCE-O.
MOVE LAST-NAME TO LAST-NAME-O.
* MOVE FIRST-NAME TO FIRST-NAME-O.
WRITE PRINT-REC.
EXIT.
*

这是 SYSOUT 输出

 Financial Report for Account holder
PREPARED ON 24.09.2020
no OF RECORDS: 00
===========================================
Maggie Bignell 8,670,838.00
Saw Eckart 8,668,500.00
Dede Quickenden 8,667,260.00
Allison Oxshott 8,593,183.00
Ambrose Inch 8,557,403.00
Leann Lob 8,656,689.00
Nevile Roswarn 8,579,721.00
Hedda Littrell 8,598,965.00
KonstantineMerner 8,557,306.00
Heddie Atwel 8,674,813.00
Torie Gimenez 8,662,345.00
Lorraine Van Hault 8,500,390.00
Javier Coltan 8,534,879.00
Kissee Kidston 8,650,707.00
Benedikta Spitell 8,589,633.00
Niles Garnson 8,649,886.00
Alair Sturrock 8,576,908.00
Tandy Pilgram 8,626,022.00
Elfrida Bamlet 8,540,474.00

IGZ0020S A logic error occurred. Neither FILE STATUS nor a declarative was specified for file CUSTRECS in program
TOPACCTS at relative location X'414'. The status code was 46.
From compile unit TOPACCTS at entry point TOPACCTS at compile unit offset +00000414 at entry offset +00000414
at address 1B800414.

最佳答案

如果您使用的是大型机 COBOL 编译器,请转到 documentation并选择您的版本。然后,您搜索“文件状态 key ”并查看文件状态 46 的含义。

A sequential READ statement was attempted on a file open in the inputor I-O mode and no valid next record had been established because:

  • The preceding READ statement was unsuccessful but did not cause an at-end condition.
  • The preceding READ statement caused an at-end condition.

请注意,在您的OPEN-FILES段落中,您执行READ-NEXT-RECORD,然后在到达文件末尾后进入其余代码。

您可能需要在第一段末尾添加 STOP RUNGOBACK

关于打印记录计数的编辑:确实没有一个好方法可以让记录计数显示在报告的顶部,因为在读取整个输入文件之前您不知道记录计数,但您'边走边重新打印报告行。大多数情况下,诸如记录计数之类的控制总数会被DISPLAY编辑(默认情况下会转到SYSOUT DD),并且报告会转到FILE-CONTROL中定义的不同DD code> (通过 WRITE,就像您正在做的那样)。

关于打印记录计数的第二次编辑:正如@GilbertLeBlanc 指出的那样,您可以将输出行存储在表中,直到您读取输入文件中的所有记录。表中必须有足够的空间来处理所有输出记录,并且有多种不同的方法可以做到这一点。

  • 您的表可以使用足够大的 OCCURS 子句进行静态定义,以处理您被告知的合理数量的记录。这在过去很常见,并且会有代码来检查是否超出了合理的数量,如果超出则异常终止。
  • 您的表格可能会出现不同的 UNBOUNDED短语,受其限制,并使用 ALLOCATE 管理存储声明和 FREE声明。
  • 您可以使用 LE Callable Services 进行自己的分配和重新分配 CEEGTST , CEEFRST ,和CEECZST .

吉尔伯特还指出,您可以读取该文件两次,一次是为了获取记录计数,然后关闭并重新打开以进行正常处理。只要您不使用 JCL 做一些棘手的事情,例如...

//TOPACCTS EXEC PGM=TOPACCTS
//SYSOUT DD SYSOUT=*
//CUSTRECS DD DISP=SHR,DSN=MY.INPUT.FILE01
//CUSTRECS DD DISP=SHR,DSN=MY.INPUT.FILE02
//CUSTRECS DD DISP=SHR,DSN=MY.INPUT.FILE03
//PRTLINE DD SYSOUT=*
//PRTLINE DD SYSOUT=*
//PRTLINE DD SYSOUT=*

...每次关闭并打开 CUST-RECS 和 PRINT-LINE 时,您都会获得下一个 DD。但这是一个更高级的 JCL 主题,您在实践中可能不会经常遇到。

关于cobol - 如何纠正 COBOL 程序 SYSOUT 假脱机中打印输出时的逻辑错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64055954/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com