正如标题所示,我在为COBOL程序获取所需输出时遇到一些困难。该程序从文件中获取数据并以特定格式输出,这用于作业。当我运行该程序时,它适用于名称标题,schoolID标题和列标题。第一个课程工作正常,然后输出开始被一个切断,并弄乱我所有的其他输出。
输入文件示例
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.
答案 0 :(得分:0)
我的COBOL非常生疏,但我不认为输入格式中的'Z'会起作用。领先的零抑制仅适用于输出格式。在对数据执行任何操作之前,您可能只需要用零替换前导空格。尝试类似:
INSPECT Earned REPLACING ALL SPACES BY '0'.
读取后(并将输入格式更改为99.99)。这是一个常见的问题,但我不记得我曾经如何处理它。