您好,我是 cobol 的初学者,需要一些功课帮助。我正在尝试编写一个在输出上打印地址标签的程序。但在输出中必须有标题、页码和日期。我已经成功地让程序以标签格式打印地址,但似乎无法让标题行(带有页面和日期)显示在其上方。使用我的程序时,会出现一个错误代码,说明我对数据文件的访问模式错误。我不确定这意味着什么。这是我的程序。我删除了日期部分只是为了尝试在地址上方获取标题行。*编辑:我已经为“打印头输出”添加了打开和关闭,但现在它给了我错误代码“文件锁定”任何人都可以对此有所了解。
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT LABEL-FILE-IN
ASSIGN TO 'C0603.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT LABEL-FILE-OUT
ASSIGN TO 'C0603.RPT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT PRINT-HEADER-OUT
ASSIGN TO 'C0603.RPT'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD LABEL-FILE-IN.
01 LABEL-RECORD-IN.
05 CUST-NAME-IN PIC X(20).
05 ADDRESS-IN PIC X(20).
05 CITY-STATE-ZIP-IN PIC X(20).
FD LABEL-FILE-OUT.
01 LABEL-RECORD-OUT.
05 PRINT-LABEL-OUT PIC X(20).
FD PRINT-HEADER-OUT.
01 REPORT-OUT PIC X(80).
WORKING-STORAGE SECTION.
01 ARE-THERE-MORE-RECORDS PIC X(3) VALUE 'YES'.
01 HEADING-LINE1.
05 PIC X(40) VALUE SPACES.
05 PIC X(12) VALUE
"MAILING LIST".
01 DATE-WS.
05 MONTH-WS PIC XX.
05 YEAR-WS PIC XX.
01 DATE-WS-OUT.
05 PIC X(45) VALUE SPACES.
05 MONTH-WS-OUT PIC XX.
05 VALUE "/".
05 YEAR-WS-OUT PIC XX.
PROCEDURE DIVISION.
000-MAIN-MODULE.
PERFORM 100-INITIALIZATION-MODULE.
PERFORM 200-PROCESS-ONE-RECORD
UNTIL ARE-THERE-MORE-RECORDS = "NO ".
PERFORM 900-TERMINATION-MODULE.
STOP RUN.
100-INITIALIZATION-MODULE.
OPEN OUTPUT PRINT-HEADER-OUT
OPEN INPUT LABEL-FILE-IN
OPEN OUTPUT LABEL-FILE-OUT
ACCEPT DATE-WS FROM DATE.
MOVE MONTH-WS TO MONTH-WS-OUT.
MOVE YEAR-WS TO YEAR-WS-OUT.
PERFORM 600-READ-MODULE.
PERFORM 300-TOP-OF-PAGE-MODULE.
200-PROCESS-ONE-RECORD.
MOVE SPACES TO PRINT-LABEL-OUT
MOVE CUST-NAME-IN TO PRINT-LABEL-OUT
WRITE LABEL-RECORD-OUT
MOVE ADDRESS-IN TO PRINT-LABEL-OUT
WRITE LABEL-RECORD-OUT
MOVE CITY-STATE-ZIP-IN TO PRINT-LABEL-OUT
WRITE LABEL-RECORD-OUT
PERFORM 600-READ-MODULE.
300-TOP-OF-PAGE-MODULE.
MOVE HEADING-LINE1 TO REPORT-OUT.
WRITE REPORT-OUT AFTER ADVANCING 9 LINES.
MOVE DATE-WS-OUT TO REPORT-OUT.
WRITE REPORT-OUT AFTER ADVANCING 1 LINES.
600-READ-MODULE.
READ LABEL-FILE-IN
AT END MOVE "NO " TO ARE-THERE-MORE-RECORDS
END-READ.
900-TERMINATION-MODULE.
CLOSE PRINT-HEADER-OUT.
CLOSE LABEL-FILE-IN.
CLOSE LABEL-FILE-OUT.