Rule Definition
When reading data from files, it is important to manage all the situations that can occur and especially when there is no data to read. If the "end of file" is not managed, then invalid data can be read and abnormal behavior can occur.
Remediation
Insert a AT END clause to READ statements in order to manage errors and end of file situations.
Violation Code Sample
1000-READ-DATA.
READ CARDIN INTO PEMPNO.
PERFORM PROCESS-DATA.
Fixed Code Sample
1000-READ-DATA.
READ CARDIN INTO PEMPNO
AT END MOVE 'N' TO INPUT-SWITCH.
IF NOMORE-INPUT
DISPLAY '++ COBDTL1C EMPTY FILE ++'
CLOSE CARDIN
ELSE
PERFORM PROCESS-DATA.
Related Technologies
Cobol
Technical Criterion
CWE-391 - Unchecked Error Condition
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.