重写cobol时出错

时间:2014-10-15 08:18:46

标签: cobol

我有代码,

IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE3.                           

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT EMP-SALARY ASSIGN TO 'input.txt'            
  ORGANIZATION IS SEQUENTIAL
  ACCESS MODE IS SEQUENTIAL.                  
DATA DIVISION.
FILE SECTION.                                    
FD EMP-SALARY.                                     
01  NEWFILE.                                     
05  FS-EMPNO  PIC 9(6).                      
05  FS-NAME   PIC 9(4).                     
05  FILLER    PIC X(63).                              
WORKING-STORAGE SECTION.
01    WS-EOF     PIC A(1)  VALUE "N".                     
PROCEDURE DIVISION.
MAIN-PARA.
OPEN I-O  EMP-SALARY                                   
PERFORM READ-PARA THRU READ-PARA-EXIT UNTIL WS-EOF="Y"
STOP RUN.  

   MAIN-PARA-EXIT.
EXIT.
   READ-PARA.
 READ EMP-SALARY               
 AT END                       
  MOVE "Y" TO WS-EOF          
 NOT AT END                   
    IF FS-EMPNO > 10000         
       MOVE '1000' TO FS-NAME

       REWRITE NEWFILE    
        DISPLAY " RECORD " NEWFILE
    END-IF 
    END-READ.

 READ-PARA-EXIT.
EXIT.

我得到的错误读取语句应该先执行Status = 43,并隐式关闭文件。

该程序用于重写文件中的记录。这个错误的原因是什么。

1 个答案:

答案 0 :(得分:2)

最好为程序中使用的任何文件包含FILE STATUS处理,并始终在IO之后测试该值。

如果这是你正在运行的代码,你必须有一个OPEN失败,READ失败,REWRITE决定它不能继续。检查它是您正在运行的代码。

您能否显示正在运行的GnuCOBOL版本以及您运行的操作系统,在程序中包含FILE STATUS并测试值,还包括文件的明确CLOSE,这始终是一种良好的做法。

看看像这样构建你的程序是否简化了:

PROCEDURE DIVISION.
    OPEN I-O  EMP-SALARY                                   
* do file status checking here
    PERFORM READ-PARA
    PERFORM PROCESS-PARA UNTIL END-OF-INPUT-FILE
* END-OF-INPUT-FILE (make the name relevant to your file) is an 88 on the FILE STATUS 
* filed for that file
* close the file
* do file status checking here
    STOP RUN
    .  
READ-PARA.
    READ EMP-SALARY               
* do file status checking here
PROCESS-PARA.
    IF FS-EMPNO > 10000         
       MOVE '1000' TO FS-NAME
       PERFORM UPDATE-RECORD
    END-IF 
    PERFORM READ-PARA
    .
UPDATE-RECORD.
    REWRITE NEWFILE    
* do file status checking here
    DISPLAY " RECORD " NEWFILE
    .