开发者

COBOL Program not writing file

开发者 https://www.devze.com 2023-02-25 08:22 出处:网络
HI all, I have a sequential file with DISP = (MOD, CATLG, CATLG) My program does an OPEN I-Oand it is supposed to write to th开发者_运维知识库e file

HI all,

I have a sequential file with DISP = (MOD, CATLG, CATLG) My program does an OPEN I-O and it is supposed to write to th开发者_运维知识库e file however, when job ends successfully, the file is still empty..

am i missing something?

FILE
REJECT   DD DSN=FILEA,         
            DISP=(MOD,CATLG,CATLG),UNIT=TESTPACK,
            DCB=(LRECL=109,BLKSIZE=0,RECFM=FB),  
            SPACE=(TRK,(3,1),RLSE)               

COBOL Program:
FD  REJECT-FILE                            
    RECORDING MODE IS F                    
    LABEL RECORDS ARE STANDARD             
    BLOCK CONTAINS 0 RECORDS               
    RECORD CONTAINS 109 CHARACTERS         
    DATA RECORD IS REJC-OUT-RECORD.        
01  REJC-OUT-RECORD             PIC X(109).


ADD-REJECTS-HEADER.                                 
    SKIP1                                           
    READ REJECT-FILE INTO RECORD-IN                 
    EVALUATE WS-STATUS                              
        WHEN '00'                                   
            CONTINUE                                
        WHEN '10'                                   
            CLOSE REJECT-FILE                       
            OPEN I-O REJECT-FILE                    
            WRITE REJC-OUT-RECORD FROM WS-HEADER-REJ
    END-EVALUATE.


You need to "CLOSE" the REJECT-FILE after your "WRITE".

Also there are many more possible condition codes than '00' and '10'.

I would suggest you replace the "WHEN '10'" with " OTHERWISE" to catch all non zero conditions.


A couple of things you should to do to make your program a bit "safer" with respect to file operations are:

1) Check and react to the FILE-STATUS on every file operation, OPEN, READ, WRITE and CLOSE.

2) Provide a catch-all for unexpected conditions. You

are only checking for "normal" and "end-of-file" conditions. A lot of other things might be indicated as well. See this reference.

It looks like you may be trying to read from and write to the same physical file. All of the I/O operations (OPEN/READ/WRITE) refer to the same file. Are you attempting to open the file for sequential access and upon reaching the end-of-file, switch to I-O then add a new record?

It would be very helpful if you showed the FILE-CONTROL paragraph as well. This will indicate how you are trying to access the file. I think there may be problems with the access mode specified under FILE-CONTROL and the OPEN/CLOSE/READ and WRITEs in the PROCEDURE DIVISION. For example, I don't see where you are specifying the record key for the I-O write operation.

Provide the FILE-CONTROL paragraph and tell us a bit more about what this program is doing. Also, give us the value of FILE-STATUS we might be able to offer more help at that point.


Has the file EVER been opened? If you just freshly allocated it with MOD, it will not have a proper EOF marker. Sometimes you will see people use IEBGENER to allocate NEW datasets an copy 0 records to them to get the EOF marker written.

0

精彩评论

暂无评论...
验证码 换一张
取 消