我的输出没有正确,我不太确定如何进行二维数组。
我的输出跟随输出应该看起来像......
如何设置二维表的好例子会有所帮助,因为不确定我在网上找到的是好的加上还没有找到一本足够好的书来解释一个老人的术语。
首先是我的代码:
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INPUT-FILE ASSIGN TO DATAIN
ORGANIZATION IS LINE SEQUENTIAL.
SELECT OUTPUT-FILE ASSIGN TO DATAOUT
ORGANIZATION IS LINE SEQUENTIAL.
SELECT ERROR-FILE ASSIGN TO DATAOUT2
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
*-------------------------------------------------------------*
* INPUT FILE LAYOUT *
*-------------------------------------------------------------*
FD INPUT-FILE.
01 INPUT-RECORD.
05 IR-JOB-NUM PIC 9(02).
88 IR-JOB-NUM-VALID VALUE 01 THRU 11.
05 IR-EMP-NUM PIC 9(01).
88 IR-EMP-NUM-VALID VALUE 1 THRU 4.
05 IR-NUM-COMPLETE PIC 9(04).
05 FILLER PIC X(03).
05 FILLER PIC X(07).
*-------------------------------------------------------------*
* OUTPUT FILE *
*-------------------------------------------------------------*
FD OUTPUT-FILE.
01 OUTPUT-RECORD PIC X(80).
*-------------------------------------------------------------*
* ERROR FILE *
*-------------------------------------------------------------*
FD ERROR-FILE.
01 ERROR-RECORD PIC X(80).
*-------------------------------------------------------------*
* WORKING STORAGE SECTION *
*-------------------------------------------------------------*
WORKING-STORAGE SECTION.
01 FLAGS-AND-ACCUMALATORS.
05 END-OF-FILE PIC XXX VALUE "NO".
88 AT-END-OF-FILE VALUE "YES".
05 ERROR-FLAG PIC XXX VALUE "NO".
05 BLANK-LINE PIC X(80) VALUE SPACES.
05 LINE-NUM-IR-POSITION PIC 999 VALUE ZERO.
01 SUBSCRIPT.
05 SUB PIC 99 VALUE ZERO.
*---------------------------------------------------------------*
* REPORT STRUCTURE *
*---------------------------------------------------------------*
* ERROR HEADER RECORD *
01 ER-HEADER.
05 FILLER PIC X(08) VALUE SPACES.
05 FILLER PIC X(03) VALUE "NO.".
05 FILLER PIC X(10) VALUE SPACES.
05 FILLER PIC X(06) VALUE "RECORD".
05 FILLER PIC X(15) VALUE SPACES.
05 FILLER PIC X(05) VALUE "ABOVE".
05 FILLER PIC X(33) VALUE SPACES.
* ERROR DETAIL RECORD *
01 ER-DETAIL-LINE.
05 FILLER PIC X(06) VALUE SPACES.
05 DL-ASTERIK PIC X(01) VALUE SPACES.
05 FILLER PIC X(01) VALUE SPACES.
05 DL-LINE-NUM PIC ZZ9 VALUE SPACES.
05 FILLER PIC X(09) VALUE SPACES.
05 DL-ERROR PIC X(16) VALUE SPACES.
05 FILLER PIC X(09) VALUE SPACES.
05 DL-ERROR-BIG-NUM PIC ZZZ9 VALUE SPACES.
* ERROR ERROR RECORD *
01 ER-ERROR-LINE.
05 FILLER PIC X(20) VALUE SPACES.
05 EL-JOB-NUM PIC X(02) VALUE SPACES.
05 EL-EMP-NUM PIC X(01) VALUE SPACES.
05 EL-NUM-COMPLETE PIC X(03) VALUE SPACES.
05 FILLER PIC X(54) VALUE SPACES.
* OUTPUT HEADER RECORD *
01 OR-HEADER.
05 FILLER PIC X(02) VALUE SPACES.
05 FILLER PIC X(03) VALUE "NO.".
05 FILLER PIC X(02) VALUE SPACES.
05 FILLER PIC X(08) VALUE "LOCATION".
05 FILLER PIC X(03) VALUE SPACES.
05 FILLER PIC X(05) VALUE " 1 ".
05 FILLER PIC X(03) VALUE SPACES.
05 FILLER PIC X(05) VALUE " 2 ".
05 FILLER PIC X(03) VALUE SPACES.
05 FILLER PIC X(05) VALUE " 3 ".
05 FILLER PIC X(03) VALUE SPACES.
05 FILLER PIC X(05) VALUE " 4 ".
05 FILLER PIC X(03) VALUE SPACES.
05 FILLER PIC X(05) VALUE "TOTAL".
05 FILLER PIC X(15) VALUE SPACES.
* OUTPUT DETAIL RECORD *
01 OR-DETAIL-LINE.
03 OR-DETAIL OCCURS 11 TIMES.
05 FILLER PIC X(02) VALUE SPACES.
05 OR-JOB-NUM PIC 9(02).
05 FILLER PIC X(03) VALUE SPACES.
05 OR-LOCATION PIC X(08) VALUE "XXXXXXXX".
05 FILLER PIC X(03) VALUE SPACES.
05 OR-EMP1-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-EMP2-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-EMP3-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-EMP4-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-JOB-TOT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(15) VALUE SPACES.
* SUMMARY RECORD *
01 OR-SUMMARY.
05 FILLER PIC X(08) VALUE SPACES.
05 FILLER PIC X(06)
VALUE "TOTALS".
05 FILLER PIC X(04) VALUE SPACES.
05 OR-TOT1-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-TOT2-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-TOT3-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-TOT4-AMT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-TOT-TOT PIC 9(05) VALUE ZEROES.
05 FILLER PIC X(15) VALUE SPACES.
PROCEDURE DIVISION.
*****************************************************************
*0000-MAIN-PROCEDURE *
*****************************************************************
0000-MAIN-PROCEDURE SECTION.
OPEN INPUT INPUT-FILE
OUTPUT OUTPUT-FILE
ERROR-FILE.
PERFORM 1000-INITIALIZE.
PERFORM UNTIL AT-END-OF-FILE
READ INPUT-FILE
AT END
MOVE 'YES' TO END-OF-FILE
NOT AT END
PERFORM 2000-PROCESS
END-READ
END-PERFORM.
PERFORM VARYING SUB FROM 1 BY 1 UNTIL SUB > 11
PERFORM 3000-FINALIZE
END-PERFORM.
PERFORM 4000-SUMMARY.
CLOSE INPUT-FILE
OUTPUT-FILE
ERROR-FILE.
GOBACK.
0000-EXIT.
EXIT.
/
*****************************************************************
*1000-INITIALIZE *
*****************************************************************
*PURPOSE: INITIALIZE ALL THE VARIABLES AND *
* WRITE THE HEADER RECORDS TO THE OUTPUT FILES. *
*****************************************************************
1000-INITIALIZE SECTION.
WRITE ERROR-RECORD FROM ER-HEADER.
WRITE ERROR-RECORD FROM BLANK-LINE.
WRITE OUTPUT-RECORD FROM OR-HEADER.
WRITE OUTPUT-RECORD FROM BLANK-LINE.
1000-EXIT.
EXIT.
/
2000-PROCESS SECTION.
*****************************************************************
*PURPOSE: *
*****************************************************************
MOVE 'NO' TO ERROR-FLAG.
ADD 1 TO LINE-NUM-IR-POSITION.
IF NOT IR-JOB-NUM-VALID
MOVE INPUT-RECORD TO DL-ERROR
MOVE LINE-NUM-IR-POSITION
TO DL-LINE-NUM
MOVE 'YES' TO ERROR-FLAG
MOVE ALL '*' TO EL-JOB-NUM
END-IF.
IF NOT IR-EMP-NUM-VALID
MOVE INPUT-RECORD TO DL-ERROR
MOVE LINE-NUM-IR-POSITION
TO DL-LINE-NUM
MOVE 'YES' TO ERROR-FLAG
MOVE ALL '*' TO EL-EMP-NUM
END-IF.
IF ERROR-FLAG = 'NO'
INSPECT IR-NUM-COMPLETE REPLACING LEADING
SPACES BY ZEROES
IF IR-NUM-COMPLETE IS NUMERIC
MOVE IR-JOB-NUM TO SUB
IF IR-EMP-NUM = 1
ADD IR-NUM-COMPLETE TO
OR-EMP1-AMT(SUB)
END-IF
IF IR-EMP-NUM = 2
ADD IR-NUM-COMPLETE TO
OR-EMP2-AMT(SUB)
END-IF
IF IR-EMP-NUM = 3
ADD IR-NUM-COMPLETE TO
OR-EMP3-AMT(SUB)
END-IF
IF IR-EMP-NUM = 4
ADD IR-NUM-COMPLETE TO
OR-EMP4-AMT(SUB)
END-IF
ELSE
MOVE INPUT-RECORD TO DL-ERROR
MOVE LINE-NUM-IR-POSITION
TO DL-LINE-NUM
MOVE 'YES' TO ERROR-FLAG
MOVE ALL '*' TO EL-NUM-COMPLETE
END-IF.
IF ERROR-FLAG = 'YES'
IF IR-NUM-COMPLETE > 50
MOVE ALL '*' TO DL-ASTERIK
MOVE IR-NUM-COMPLETE TO DL-ERROR-BIG-NUM
END-IF
WRITE ERROR-RECORD FROM ER-DETAIL-LINE
WRITE ERROR-RECORD FROM ER-ERROR-LINE
MOVE SPACES TO ER-DETAIL-LINE
MOVE SPACES TO ER-ERROR-LINE
END-IF.
2000-EXIT.
EXIT.
/
3000-FINALIZE SECTION.
*****************************************************************
*PURPOSE: *
*****************************************************************
MOVE SUB TO OR-JOB-NUM(SUB).
ADD OR-EMP1-AMT(SUB)
OR-EMP2-AMT(SUB)
OR-EMP3-AMT(SUB)
TO OR-EMP4-AMT(SUB)
GIVING OR-JOB-TOT(SUB).
ADD OR-EMP1-AMT(SUB) TO OR-TOT1-AMT.
ADD OR-EMP2-AMT(SUB) TO OR-TOT2-AMT.
ADD OR-EMP3-AMT(SUB) TO OR-TOT3-AMT.
ADD OR-EMP4-AMT(SUB) TO OR-TOT4-AMT.
ADD OR-JOB-TOT(SUB) TO OR-TOT-TOT.
IF OR-JOB-TOT(SUB) > 0
WRITE OUTPUT-RECORD FROM OR-DETAIL(SUB)
WRITE OUTPUT-RECORD FROM BLANK-LINE
END-IF.
3000-EXIT.
EXIT.
/
4000-SUMMARY SECTION.
*****************************************************************
*PURPOSE: *
*****************************************************************
WRITE OUTPUT-RECORD FROM BLANK-LINE.
WRITE OUTPUT-RECORD FROM OR-SUMMARY.
4000-EXIT.
EXIT.
“异常”报告中的输出是: 没有。上面的记录
3 0r4000700 03
**
6 074000Q00 06
***
* 7 075075000 07 750
*
* 8 06105 100 08 5 1
***
10 095000500 10
*
* 12 125999999 12 9999
***
19 08500050 19
*
21 125000899 21
***
23 A01001111 23
**
但应该是: 错误报告
NO. CONTENTS ABOVE
2 032 200 02
****
3 0r4000700 03
**
5 073 73000 05
****
6 074000Q00 06
****
* 7 075075000 07 750
*
8 06105 100 08
****
9 011 52000 09
****
10 095000500 10
*
* 12 125999999 12 9999
***
19 08500050 19
*
* 20 091010000 20 100
21 125000899 21
***
23 A01001111 23
**
我的摘要输出是:
NO. LOCATION 1 2 3 4 TOTAL 01 XXXXXXXX 00520 00000 00000 00000 00520 03 XXXXXXXX 00000 00002 00000 00007 00009 04 XXXXXXXX 00010 00010 00003 00000 00023 05 XXXXXXXX 00000 00012 00000 00004 00016 06 XXXXXXXX 00000 00000 00000 00004 00004 07 XXXXXXXX 00000 00000 00730 00000 00730 08 XXXXXXXX 00006 00000 00000 00004 00010 09 XXXXXXXX 00100 00000 00000 00000 00100 TOTALS 00636 00024 00733 00019 01412
应该是这样的:
SUMMARY REPORT NO. LOCATION 1 2 3 4 TOTAL 1 PETERS, FL 0 0 0 0 0 2 ATCHISON, KS 0 0 0 0 0 3 KANSAS CITY, MO 0 0 0 7 7 4 DENVER, CO 10 10 3 0 23 5 SAN JOSE, CA 0 12 0 4 16 6 REDMOND, WA 0 0 0 4 4 7 HOUSTON, TX 0 0 0 0 0 8 TOPEKA, KS 6 0 0 4 10 9 WICHITA, KS 100 0 0 0 100 10 JEFFERSON CITY, MO 0 0 0 0 0 11 ST. LOUIS MO 0 0 0 0 0 TOTALS 116 22 3 19 160
答案 0 :(得分:1)
对于Cobol中的多维数组,只需嵌套出现的子句:
01 WS-DETAIL-totals OCCURS 11 TIMES.
05 WS-JOB-NUM PIC 9(02).
05 WS-LOCATION PIC X(08) VALUE "XXXXXXXX".
05 WS-EMP-AMT occurs 4 PIC s9(05) COMP VALUE ZEROES.
05 WS-JOB-TOT PIC s9(05) COMP VALUE ZEROES.
01 OR-DETAIL-LINE.
03 OR-DETAIL OCCURS 11 TIMES.
05 FILLER PIC X(02) VALUE SPACES.
05 OR-JOB-NUM PIC z9.
05 FILLER PIC X(03) VALUE SPACES.
05 OR-LOCATION PIC X(08) VALUE "XXXXXXXX".
05 FILLER PIC X(03) VALUE SPACES.
05 Filler occurs 4.
10 OR-EMP1-AMT PIC ----9.
10 FILLER PIC X(03) VALUE SPACES.
05 OR-JOB-TOT PIC ----9 VALUE ZEROES.
05 FILLER PIC X(15) VALUE SPACES.
你应也会累积在 comp 字段中(例如上面的ws表格中)并转移到输出表格。
在
INSPECT IR-NUM-COMPLETE REPLACING LEADING
SPACES BY ZEROES
2000年的声明 - 意味着未捕获如下错误
2 032 200 02
****