タイトルが示すように、COBOL プログラムの目的の出力を取得するのに苦労しています。プログラムはファイルからデータを取り込み、特定の形式で出力します。これは宿題用です。プログラムを実行すると、名前ヘッダー、schoolID ヘッダー、および列ヘッダーに対して機能します。最初のコースは正常に機能し、その後、出力が 1 つずつカットされ始め、他のすべての出力が台無しになります。
入力ファイルの例
CMPS161 ALGORITHM DSGN/IMPLMNT I A 3.00
CMPS280 ALGORITHM DSGN/IMPLEM II B 3.00
出力ファイル希望例
<Name>
<schoolID>
Course Title GR Earned
CMPS161 ALGORITHM DSGN/IMPLMNT I A 3.00
CMPS280 ALGORITHM DSGN/IMPLEM II B 3.00
出力実績例
<Name>
<schoolID>
Course Title GR Earned
CMPS161 ALGORITHM DSGN/IMPLMNT I A 0.00
MPS280 ALGORITHM DSGN/IMPLEM II B 0.00
COBOLプロジェクト
IDENTIFICATION DIVISION.
PROGRAM-ID. P2.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT myInFile ASSIGN TO "P2In.dat".
SELECT myOutFile ASSIGN TO "P2Out.dat".
DATA DIVISION.
FILE SECTION.
FD myInFile.
01 inRecord.
02 Course PIC X(13).
02 Title PIC X(32).
02 Grade PIC X(4).
02 Earned PIC Z9.99.
02 FILLER PIC X(3).
FD myOutFile.
01 outRecord.
02 myCourse PIC X(13).
02 myTitle PIC X(32).
02 myGrade PIC X(4).
02 myEarned PIC Z9.99.
02 FILLER PIC X(3).
WORKING-STORAGE SECTION.
01 E0F PIC X(3) VALUE "NO ".
01 NAME-HDR.
05 FILLER PIC X(10) VALUE "NAME HERE ".
01 SCHOOLID-HDR.
05 FILLER PIC X(8) VALUE "SCHOOLID"
01 COLUMN-HDR.
05 FILLER PIC X(6) VALUE "COURSE".
05 FILLER PIC X(6) VALUE SPACES.
05 FILLER PIC X(6) VALUE "TITLE".
05 FILLER PIC X(6) VALUE SPACES.
05 FILLER PIC X(6) VALUE "GR".
05 FILLER PIC X(6) VALUE SPACES.
05 FILLER PIC X(6) VALUE "EARNED".
PROCEDURE DIVISION.
MAIN-PROGRAM.
PERFORM HEADER.
PERFORM FILE-IO.
PERFORM CLOSING.
STOP RUN.
HEADER.
OPEN INPUT myInFile
OUTPUT myOutFile.
WRITE outRecord FROM NAME-HDR
AFTER ADVANCING 1 LINE.
WRITE outRecord FROM SCHOOLID-HDR
AFTER ADVANCING 1 LINE.
WRITE outRecord FROM COLUMN-HDR
AFTER ADVANCING 2 LINES.
MOVE SPACES TO outRecord.
WRITE outRecord
AFTER ADVANCING 1 LINE.
FILE-IO.
READ myInFile
AT END
MOVE "YES" TO EOF.
PERFORM PROCESS-RECORD
UNTIL EOF = "YES".
PROCESS-RECORD.
MOVE SPACES TO outRecord.
MOVE Course to myCourse.
MOVE Title to myTitle.
MOVE Grade to myGrade.
MOVE Earned to myEarned.
WRITE outRecord
AFTER ADVANCING 1 LINE.
READ myInFile
AT END
MOVE "YES" TO EOF.
CLOSING.
CLOSE myInFile
myOutFile.