Skip to main content

How to restore logically deleted records in a C-ISAM indexed file

  • February 15, 2013
  • 0 replies
  • 0 views

Problem:

When you delete a record from a C-ISAM index file, it doesn't phisically disappear straight away. That record gets marked as deleted but the information is still there, although it can not be accessed to by a COBOL program or any tool.

Within time that free space may be used to store new records and the information that was there before is then completely lost.

But while the information is still there, you may want to undelete a deleted record if it happened by mistake and there are no backups of the file.

This behaviour is similar for files with Micro Focus format instead of C-ISAM.

Resolution:

Currently there is no tool in the products to do this.

As we don't own the CISAM format we can not give you the information about its internal structure, but if you edit the data part of the file with a hexadecimal editor you will see that at the end of each record there is an extra byte that can contain:

  - the value x"0A" for a normal record

  - the value x"00" for a deleted record

You can edit the data part of the file or with an hexadecimal editor (there are quite a few freeware on the web) and change by hand the value x"00" to the value x"0A", or you can edit the file with a COBOL program where:

- you define the file as organization RECORD SEQUENTIAL

- give the record one extra field at the end to read the extra byte:

    01 myrecord.

       05 field1...

       .....

       05 extra-byte pic X.

- define an output file with exactly the same organization and exactly the same record structure.

- read the file from beginning to end writing every record you read and when you get to a record where extra-byte = x"00" and that you want to undelete, then you write it in the output file changing extra-byte to x"0A".

Once you run this program, you can copy the output file over the original file.

Whichever method you use, an hexadecimal editor or a COBOL program, you would have changed only the data part of the file and not the .idx part of the file, which means that the file is now corrupt. If you run:

   rebuild myfile -f

you will see that there are inconsistencies between the data and the index file.

To correct this, simply run rebuild on the file:

   rebuild myfile

and that should do the trick. Check that everything is fine with rebuild -f again.

Obviously, this is not a very orthodox way of updating the file, so I recommend you to make a backup of the file before you do anything on it.

Old KB# 5000

#COBOL
#netexpress
#RMCOBOL
#AcuCobol
#ServerExpress