我試圖寫COBOL程序順序讀取平面文件並將其寫入輸出文件,我一次只能讀取一條記錄,無法讀取下一個記錄,我該怎麼辦?COBOL程序順序讀取平面文件並將其寫入輸出文件,無法讀取所有循環將無限
這裏是我的代碼:
PROCEDURE DIVISION.
OPEN INPUT FILEX.
PERFORM READ-PARA THRU END-PARA UNTIL END-OF-FILE = 'Y'.
CLOSE FILEX.
STOP RUN.
READ-PARA.
READ FILEX
AT END
MOVE 'Y' TO END-OF-FILE
DISPLAY OFFCODE1
DISPLAY AGCODE1
DISPLAY POLNO1
DISPLAY EFFDATE1
DISPLAY EXPDATE
DISPLAY REPCODE
DISPLAY POLHOLDER1
DISPLAY LOCATION1
GO TO END-PARA.
END-PARA.
我,已經使用範圍終止試過了,仍然無法循環「M越來越S001 ABEND這裏是我的代碼:
IDENTIFICATION DIVISION.
PROGRAM-ID. SIMPLE.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT FILEX ASSIGN TO SYSUT1
FILE STATUS IS FS.
DATA DIVISION.
FILE SECTION.
FD FILEX.
01 FILEXREC.
02 OFFCODE1 PIC X(3).
02 FILLER PIC X.
02 AGCODE1 PIC X(3).
02 FILLER PIC X.
02 POLNO1 PIC X(6).
02 FILLER PIC X.
02 EFFDATE1 PIC X(8).
02 FILLER PIC X.
02 EXPDATE PIC X(8).
02 FILLER PIC X.
02 REPCODE PIC X(1)
02 FILLER PIC X.
02 POLHOLDER1 PIC X(8).
02 FILLER PIC X.
02 LOCATION1 PIC X(9).
02 FILLER PIC X(87).
WORKING-STORAGE SECTION.
77 FS PIC 9(2).
01 WS-INDICATORS.
10 WS-EOF-IND PIC X(01) VALUE 'N'.
88 WS-END-OF-FILE VALUE 'Y'.
PROCEDURE DIVISION.
OPEN INPUT FILEX.
PERFORM READ-PARA THRU END-PARA UNTIL WS-END-OF-FILE.
CLOSE FILEX.
STOP RUN.
READ-PARA.
READ FILEX
AT END
MOVE 'Y' TO WS-EOF-IND.
DISPLAY OFFCODE1
DISPLAY AGCODE1
DISPLAY POLNO1
DISPLAY EFFDATE1
DISPLAY EXPDATE
DISPLAY REPCODE
DISPLAY POLHOLDER1
DISPLAY LOCATION1
IF WS-END-OF-FILE
GO TO END-PARA.
END-PARA.
EXIT.
多一個方法我甚至在這個作品中只嘗試了一條記錄,在運行代碼時再次獲得S001 ABEND。下面是代碼:
IDENTIFICATION DIVISION.
PROGRAM-ID. ASSIGNMENT.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT FILEX ASSIGN TO SYSUT1
DATA DIVISION.
FILE SECTION.
FD FILEX.
LABEL RECORDS ARE STANDARD
RECORD CONTAINS 140 CHARACTERS
BLOCK CONTAINS 00 RECORDS.
01 FILEXREC.
02 OFFCODE1 PIC 9(3).
02 FILLER PIC X.
02 AGCODE1 PIC X(3).
02 FILLER PIC X.
02 POLNO1 PIC X(6).
02 FILLER PIC X.
02 EFFDATE1 PIC X(8).
02 FILLER PIC X.
02 EXPDATE1 PIC X(8).
02 FILLER PIC X.
02 REPCODE1 PIC X(1).
02 FILLER PIC X.
02 POLHOLDER1 PIC X(8).
02 FILLER PIC X.
02 LOCATION1 PIC X(9).
02 FILLER PIC X(26).
WORKING-STORAGE SECTION.
01 WS-INDICATORS.
10 WS-EOF-IND PIC X(01) VALUE 'N'.
88 WS-END-OF-FILE VALUE 'Y'.
01 TEMP1.
02 OFFCODE2 PIC 9(3).
02 FILLER PIC X.
02 AGCODE2 PIC X(3).
02 FILLER PIC X.
02 POLNO2 PIC X(6).
02 FILLER PIC X.
02 EFFDATE2 PIC X(8).
02 FILLER PIC X.
02 EXPDATE2 PIC X(8).
02 FILLER PIC X.
02 REPCODE2 PIC X(1).
02 FILLER PIC X.
02 POLHOLDER2 PIC X(8).
02 FILLER PIC X.
02 LOCATION2 PIC X(9).
02 FILLER PIC X(26).
PROCEDURE DIVISION.
OPEN INPUT FILEX.
PERFORM READ-PARA THRU END-PARA UNTIL WS-END-OF-FILE.
CLOSE FILEX.
STOP RUN.
READ-PARA.
READ FILEX
INTO TEMP1
AT END
MOVE 'Y' TO WS-EOF-IND.
DISPLAY OFFCODE1
DISPLAY AGCODE1
DISPLAY POLNO1
DISPLAY EFFDATE1
DISPLAY EXPDATE1
DISPLAY REPCODE1
DISPLAY POLHOLDER1
DISPLAY LOCATION1
IF WS-END-OF-FILE
GO TO END-PARA.
END-PARA.
EXIT.
+1 ..你的回答是正確的。從AT END到下一句(即直到END TO PARA之後的時間段)的所有代碼均落入AT END短語的範圍內。正如你所示,END-READ應該總是用來限制READ語句的範圍。 – NealB 2012-07-10 13:25:37
+1 ..我會更進一步。如果END- *可用,則應完全避免除標籤末尾所需段之外的所有時段,並且還應完全避免PERFORM中的任何THRU子句。混合74式控制和終止與85式控制和終止永遠是一個跆拳道?!?發電機。 – 2012-07-10 16:00:33
嗨,感謝您的回覆,不幸的是它並沒有爲我工作,因爲他們在這裏使用舊版本的COBOL COBOL-2,所以仍然在尋找如何循環 – 2012-07-11 10:12:01