您好,并提前感谢您的帮助。我是COBOL经验有限的导师。我已将变量名称概括为不发布学校作业的答案。
此处显示的文件输出
是完美的,但没有这个黑客行
05 FILLER PIC X VALUE X'0d'.
在要写入文件的每个组的末尾,不会有任何回车,因此所有数据都显示在一行上。
我和我的学生也非常感谢您提供的任何其他有用的评论或资源。
再次感谢。
environment division.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT FILE-IN
ASSIGN TO 'IN.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT FILE-OUT
ASSIGN TO 'OUT.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
data division.
FILE SECTION.
FD IN.
01 FILE-IN.
05 FILE-1-IN PIC X(20).
05 FILE-2-IN PIC 9(3).
05 FILE-3-IN PIC 9(3).
05 FILE-4-IN PIC 9(3).
05 FILE-5-IN PIC 9(4).
FD INVENT-REPORT-OUT.
01 FILE-1-OUT PIC X(150).
working-storage section.
01 WS-IN.
05 WS-1-IN PIC X(20).
05 WS-2-IN PIC 9(3).
05 WS-3-IN PIC 9(3).
05 WS-4-IN PIC 9(3).
05 WS-5-IN PIC 9(4).
*TOTAL OF 78 BYTES
01 WS-1-LINE-OUT.
05 FILLER PIC X(2) VALUE SPACE.
05 WS-1-OUT PIC X(20).
05 FILLER PIC X(2) VALUE SPACE.
05 WS-2-OUT PIC 9(3).
05 FILLER PIC X(6) VALUE SPACE.
05 WS-3-OUT PIC 9(3).
05 FILLER PIC X(7) VALUE SPACE.
05 WS-4-OUT PIC 9(3).
05 FILLER PIC X(7) VALUE SPACE.
05 WS-5-OUT PIC 9(4).
05 FILLER PIC X(8) VALUE SPACE.
05 WS-6-OUT PIC 9(4).
05 FILLER PIC X(3) VALUE SPACE.
05 WS-7-OUT PIC 9(6).
05 FILLER PIC X VALUE X'0d'.
01 WS-TOTAL-LINE-OUT.
05 FILLER PIC X(16) VALUE " TOTAL VALUE ".
05 WS-TOTAL-OUT PIC 9(10).
05 FILLER PIC X VALUE X'0d'.
*TOTAL OF 78 LINES
01 WS-HEADER-LINE-OUT.
05 FILLER PIC X(2) VALUE SPACE.
05 FILLER PIC X(22) VALUE "DATA".
05 FILLER PIC X(9) VALUE "DATA".
05 FILLER PIC X(10) VALUE "DATA".
05 FILLER PIC X(10) VALUE "DATA".
05 FILLER PIC X(12) VALUE "DATA".
05 FILLER PIC X(7) VALUE "DATA".
05 FILLER PIC X(6) VALUE "DATA".
05 FILLER PIC X VALUE X'0d'.
01 WS-SEPERATOR-LINE-OUT.
05 FILLER PIC X(2) VALUE SPACE.
05 FILLER PIC X(20) VALUE " / / / / / / / / / /".
05 FILLER PIC X(20) VALUE " / / / / / / / / / /".
05 FILLER PIC X(20) VALUE " / / / / / / / / / /".
05 FILLER PIC X(16) VALUE " / / / / / / / /".
05 FILLER PIC X VALUE X'0d'.
01 WS-EMPTY-LINE-OUT.
05 FILLER PIC X(78) VALUE SPACES.
05 FILLER PIC X VALUE X'0d'.
77 WS-COUNT-READ PIC 9(3) VALUE 0.
77 WS-COUNT-WRITE PIC 9(3) VALUE 0.
77 WS-EOF PIC 9(1) VALUE 0.
77 WS-MODULUS-RESULT PIC 9(1) VALUE 0.
procedure division.
100-MAIN-PROCEDURE.
OPEN OUTPUT FILE-OUT.
OPEN INPUT FILE-IN.
PERFORM 310-WRITE-EMPTY-LINE.
PERFORM 310-WRITE-EMPTY-LINE.
MOVE WS-HEADER-LINE-OUT TO FILE-LINE-OUT.
WRITE FILE-LINE-OUT.
PERFORM 310-WRITE-EMPTY-LINE.
PERFORM UNTIL WS-EOF = 1
ADD 1 TO WS-COUNT-READ
READ INVENT-FILE-IN INTO WS-IN
AT END MOVE 1 TO WS-EOF
NOT AT END PERFORM 200-CALC-WRITE-RECORD
END-READ
END-PERFORM.
PERFORM 310-WRITE-EMPTY-LINE
MOVE WS-TOTAL-LINE-OUT TO FILE-LINE-OUT.
WRITE FILE-LINE-OUT.
CLOSE INVENT-FILE-IN.
CLOSE INVENT-REPORT-OUT.
STOP RUN.
200-CALC-WRITE-RECORD.
*DO SOME MATH HERE
*MOVE ALL UNCHANGED VALUES
MOVE WS-1-LINE-OUT TO
FILE-LINE-OUT.
WRITE FILE-LINE-OUT.
ADD 1 TO WS-COUNT-WRITE.
COMPUTE WS-MODULUS-RESULT = FUNCTION MOD (WS-COUNT-WRITE, 8).
IF WS-MODULUS-RESULT = 0
MOVE WS-EMPTY-LINE-OUT TO FILE-LINE-OUT
PERFORM 300-WRITE-LINE-OUT
MOVE WS-SEPERATOR-LINE-OUT TO FILE-LINE-OUT
PERFORM 300-WRITE-LINE-OUT
PERFORM 300-WRITE-LINE-OUT
PERFORM 300-WRITE-LINE-OUT
PERFORM 300-WRITE-LINE-OUT
MOVE WS-EMPTY-LINE-OUT TO FILE-LINE-OUT
PERFORM 300-WRITE-LINE-OUT.
300-WRITE-LINE-OUT.
WRITE FILE-LINE-OUT.
310-WRITE-EMPTY-LINE.
MOVE WS-EMPTY-LINE-OUT TO FILE-LINE-OUT
PERFORM 300-WRITE-LINE-OUT.
end program PROGRAM.