Monday, 28 July 2014

COBOL Invalid Key Clause.

A clause that can be used with READ, WRITE and REWRITE statement for indexed files; check that disk records have valid keys fields. 

When INVALID KEY is coded with a WRITE statement to test for two possible errors : 

  • a key field that is not in sequence.
  • a key field has duplicate value. 
  • a key field has blank value. 

If any of above condition exists, the INVALID KEY clause will be called and imperative statement mention in INVALID KEY section will be executed. 

Format : 


The Invalid Key clause of the Read, Write, and Rewrite statements is executed whenever an invalid key condition occurs (file status 21, 22, 23, or 24). If an invalid key condition doesn’t occur, the Not Invalid Key clause is executed.

Example : 



Created with Artisteer

No comments:

Post a Comment