IDENTIFICATION DIVISION.
PROGRAM-ID. HENSEM as "Test1.Program1".
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT CUSTOMER-FILE
ASSIGN TO "CUSTOMER.DAT"
ORGANIZATION IS SEQUENTIAL.
SELECT PRINTER-FILE
ASSIGN TO PRINTER
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD CUSTOMER-FILE
LABEL RECORDS ARE STANDARD.
01 CUSTOMER-RECORD.
05 CUSTOMER-NAME PIC X(30).
05 CUSTOMER-PRODUCT PIC X(20).
05 CUSTOMER-QUANTITY PIC 9(2).
05 CUSTOMER-DATE PIC X(10).
FD PRINTER-FILE
LABEL RECORDS ARE OMITTED.
01 PRINTER-RECORD PIC X(80).
WORKING-STORAGE SECTION.
*VARIABLES FOR SCREEN ENTRY
01 Y-N PIC X.
01 ENTRY-STATUS PIC X.
PROCEDURE DIVISION.
OPEN EXTEND CUSTOMER-FILE.
OPEN OUTPUT PRINTER-FILE.
MOVE "Y" TO Y-N.
PERFORM ADD-RECORDS
UNTIL Y-N = "N".
PERFORM CLOSING-PROCEDURE.
GOBACK.
* OPENING AND CLOSING
OPENING-PROCEDURE.
CLOSING-PROCEDURE.
CLOSE CUSTOMER-FILE.
MOVE SPACE TO PRINTER-RECORD.
WRITE PRINTER-RECORD BEFORE ADVANCING PAGE.
CLOSE PRINTER-FILE.
ADD-RECORDS.
MOVE "N" TO ENTRY-STATUS.
PERFORM GET-FIELDS
UNTIL ENTRY-STATUS = "Y".
PERFORM ADD-THIS-RECORD.
PERFORM ANY-MORE.
GET-FIELDS.
MOVE SPACE TO CUSTOMER-RECORD.
DISPLAY "ENTER CUSTOMER NAME: ".
ACCEPT CUSTOMER-NAME.
DISPLAY "ENTER WHAT DID THE CUSTOMER BOUGHT: ".
ACCEPT CUSTOMER-PRODUCT.
DISPLAY "ENTER HOW MUCH DID THE CUSTOMER BOUGHT: ".
ACCEPT CUSTOMER-QUANTITY.
DISPLAY "ENTER WHEN DID THE CUSTOMER BOUGHT: ".
ACCEPT CUSTOMER-DATE.
PERFORM VALIDATE-FIELDS.
VALIDATE-FIELDS.
MOVE "Y" TO ENTRY-STATUS.
IF CUSTOMER-NAME = SPACE
DISPLAY "CUSTOMER NAME MUST BE ENTERED"
MOVE "N" TO ENTRY-STATUS.
ADD-THIS-RECORD.
MOVE CUSTOMER-RECORD TO PRINTER-RECORD.
WRITE CUSTOMER-RECORD.
WRITE PRINTER-RECORD BEFORE ADVANCING 1.
ANY-MORE.
DISPLAY "IS THERE ANY MORE INPUT?".
ACCEPT Y-N.
IF Y-N = "Y"
MOVE "Y" TO Y-N.
IF Y-N NOT = "Y"
MOVE "N" TO Y-N.
END PROGRAM HENSEM.
我的问题是OPEN OUTPUT FILE-PRINTER LINE。程序没有运行,我收到了非法的文件名错误。如果我删除整行,它会运行但后来在WRITE PRINTER-RECORD出现之前产生错误1.谢谢。
答案 0 :(得分:4)
您可以assign a device name to your file使用其中一个标准Windows符号名称,而不是COBOL关键字PRINTER:
SELECT PRINTER-FILE
ASSIGN TO "lpt1"
ORGANIZATION IS LINE SEQUENTIAL.