如何纠正 COBOL 程序在 SYSOUT 假脱机中打印输出时的逻辑错误?
How do I rectify this logical error in printing output in the SYSOUT spool from COBOL program?
这是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 和 select 您的版本。然后搜索“文件状态键”并查看文件状态 46 的含义。
A sequential READ statement was attempted on a file open in the input
or 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
段落中,您 PERFORM READ-NEXT-RECORD
然后在已经到达文件末尾后陷入代码的其余部分。
您可能希望在第一段末尾使用 STOP RUN
或 GOBACK
。
关于打印记录数的编辑:确实没有一种好方法可以让记录数出现在报告的顶部,因为在阅读整个输入文件之前您不知道记录数,但是您正在打印报告行。大多数时间控制总计如记录计数是 DISPLAY
ed(默认情况下转到 SYSOUT DD)并且报告转到 FILE-CONTROL
中定义的不同 DD(通过 WRITE
,就像你正在做的那样)。
关于打印记录计数的第二次编辑:正如@GilbertLeBlanc 指出的那样,您可以将输出行存储在 table 中,直到您读取了输入文件中的所有记录。您必须在 table 中有足够的 space 来处理所有输出记录,并且有许多不同的方法可以做到这一点。
- 您的 table 可以静态定义一个足够大的
OCCURS
子句来处理您被告知的合理数量的记录。这个以前很常见,会有代码检查是否超过了合理的数量,如果超过了就abend。
- 您的 table 可能会随
UNBOUNDED
phrase, subject to its limitations, and storage managed with the ALLOCATE
statement and FREE
语句发生变化。
- 您可以使用 LE Callable Services CEEGTST, CEEFRST, and CEECZST 滚动您自己的分配和重新分配。
Gilbert 还指出您可以读取文件两次,一次获取记录计数,然后关闭并重新打开以进行正常处理。只要您不对 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代码
*-----------------------
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 和 select 您的版本。然后搜索“文件状态键”并查看文件状态 46 的含义。
A sequential READ statement was attempted on a file open in the input or 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
段落中,您 PERFORM READ-NEXT-RECORD
然后在已经到达文件末尾后陷入代码的其余部分。
您可能希望在第一段末尾使用 STOP RUN
或 GOBACK
。
关于打印记录数的编辑:确实没有一种好方法可以让记录数出现在报告的顶部,因为在阅读整个输入文件之前您不知道记录数,但是您正在打印报告行。大多数时间控制总计如记录计数是 DISPLAY
ed(默认情况下转到 SYSOUT DD)并且报告转到 FILE-CONTROL
中定义的不同 DD(通过 WRITE
,就像你正在做的那样)。
关于打印记录计数的第二次编辑:正如@GilbertLeBlanc 指出的那样,您可以将输出行存储在 table 中,直到您读取了输入文件中的所有记录。您必须在 table 中有足够的 space 来处理所有输出记录,并且有许多不同的方法可以做到这一点。
- 您的 table 可以静态定义一个足够大的
OCCURS
子句来处理您被告知的合理数量的记录。这个以前很常见,会有代码检查是否超过了合理的数量,如果超过了就abend。 - 您的 table 可能会随
UNBOUNDED
phrase, subject to its limitations, and storage managed with theALLOCATE
statement andFREE
语句发生变化。 - 您可以使用 LE Callable Services CEEGTST, CEEFRST, and CEECZST 滚动您自己的分配和重新分配。
Gilbert 还指出您可以读取文件两次,一次获取记录计数,然后关闭并重新打开以进行正常处理。只要您不对 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 主题,您在实践中可能不会 运行 经常参与。