# INVALID KEY on Rewrite to a Logical file

**URL:** <https://community.openmainframeproject.org/t/invalid-key-on-rewrite-to-a-logical-file/5904>\
**Category:** COBOL technical questions\
**Created:** [July 17, 2020, 4:11am UTC](https://community.openmainframeproject.org/t/invalid-key-on-rewrite-to-a-logical-file/5904 "2020-07-17T04:11:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nutz4fanz](https://avatars.discourse-cdn.com/v4/letter/n/0ea827/32.png) [@nutz4fanz](https://community.openmainframeproject.org/u/nutz4fanz)\
**Post date:** [July 17, 2020, 4:11am UTC](https://community.openmainframeproject.org/t/invalid-key-on-rewrite-to-a-logical-file/5904/1 "2020-07-17T04:11:50Z")

</div>

Hi, I am getting an Invalid key status of 20 when trying to do a REWRITE on a Logical file. The program had initially performed a successful read on the record. What would be causing this? Thank you for any inputs.

---

<div class="post-metadata">

**Author:** ![jim](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jim](https://community.openmainframeproject.org/u/jim)\
**Post date:** [July 17, 2020, 5:38pm UTC](https://community.openmainframeproject.org/t/invalid-key-on-rewrite-to-a-logical-file/5904/2 "2020-07-17T17:38:18Z")

</div>

Hi - is this Micro Focus or on the mainframe?

---

<div class="post-metadata">

**Author:** ![Cobolskolan](https://avatars.discourse-cdn.com/v4/letter/c/b38774/32.png) [@Cobolskolan](https://community.openmainframeproject.org/u/Cobolskolan)\
**Post date:** [July 18, 2020, 3:48pm UTC](https://community.openmainframeproject.org/t/invalid-key-on-rewrite-to-a-logical-file/5904/3 "2020-07-18T15:48:11Z")

</div>

Have you checked your record to see that the key is correct? Just Display before Rewrite.

---

<div class="post-metadata">

**Author:** ![YES](https://avatars.discourse-cdn.com/v4/letter/y/ea5d25/32.png) [@YES](https://community.openmainframeproject.org/u/YES)\
**Post date:** [July 19, 2020, 3:15pm UTC](https://community.openmainframeproject.org/t/invalid-key-on-rewrite-to-a-logical-file/5904/4 "2020-07-19T15:15:36Z")

</div>

Or the key has changed… check before and after  
**20** Device or resource busy (Micro Focus). record key values has been violated, or, the prime record key value has been changed by a **COBOL** program between successful execution of a READ statement and execution of the next **REWRITE** statement for that file.

---

<div class="post-metadata">

**Author:** ![nutz4fanz](https://avatars.discourse-cdn.com/v4/letter/n/0ea827/32.png) [@nutz4fanz](https://community.openmainframeproject.org/u/nutz4fanz)\
**Post date:** [August 8, 2020, 4:39am UTC](https://community.openmainframeproject.org/t/invalid-key-on-rewrite-to-a-logical-file/5904/5 "2020-08-08T04:39:58Z")

</div>

This is COBOL 400. Thanks

---

<div class="post-metadata">

**Author:** ![nutz4fanz](https://avatars.discourse-cdn.com/v4/letter/n/0ea827/32.png) [@nutz4fanz](https://community.openmainframeproject.org/u/nutz4fanz)\
**Post date:** [August 8, 2020, 4:41am UTC](https://community.openmainframeproject.org/t/invalid-key-on-rewrite-to-a-logical-file/5904/6 "2020-08-08T04:41:04Z")

</div>

Thank you for your help.
