Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 10: File processing

File Error- Handling

  • When we perform any I-O operations on file, there are chances that it may fail
  • COBOL itself does not automatically take corrective action, we have to choose whether our program should continue running after error or not. The severity of error has to be defined in the program design stage.
  • Let’s assume that we don’t have any file error handling. In such case, if READ operation is done and end of file is reached, the program will be terminated immediately with error “End of file”
  • Some techniques to handle certain I-O errors are:-
    1. Use of Error-Handling clauses provided by COBOL
      • There are certain error handling clauses are provided by COBOL which can be used to handle file errors.
      • AT END is used to handle error when read reaches to the end of file
      • INVALID KEY is used to handle error when record is not found for specified key and thus cause execution of imperative statement.
    2. FILE STATUS clause and file-status key
      • In this technique, we can assign file-status to the file in the SELECT clause and verify the file status after every I-O and ensure it has permitted values. If not, then abnormally end the program with some display statement to make debugging easier.
  • FILE STATUS CODE and it's meaning is listed here.

© copyright mainframebug.com
Privacy Policy