Microsoft KB Archive/60144

READ SEQUENTIAL Is Alternative to Rebuild Corrupt ISAM File

PSS ID Number: Q60144 Article last modified on 06-13-1990

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: It is often possible to recover a corrupted ISAM file if the file has not been too badly damaged. REBUILD.EXE is a utility provided for this purpose with Microsoft COBOL versions 3.00 and 3.00a. As an alternative to REBUILD, you can recover the file by sequentially reading in the data from the ISAM .DAT file, then writing the data out to a new ISAM file. This article contains a sample program that rebuilds an ISAM file by sequentially reading in the original .DAT file and creating a new ISAM file. This information applies to Microsoft COBOL versions 3.00 and 3.00a for MS-DOS and MS OS/2.

More Information: This article illustrates the method described on Page 7-17 of the “Microsoft COBOL Compiler 3.0: Operating Guide” for versions 3.00 and 3.00a. This method will work to rebuild ISAM files made with fixed-length or variable-length records. When an ISAM file is created, there are actually two files created. One of the files created is the ISAM key file, which has an .IDX extension. The other file contains the data and has whatever extension is specified by the programmer, usually .DAT. ISAM .DAT files have a structure very similar to files that were created with ORGANIZATION SEQUENTIAL, except they may have a larger header. For more information about the structure of SEQUENTIAL data (.DAT) files in Microsoft COBOL versions 3.00 and 3.00a, query in this Knowledge Base on the following words: rebuild and 3.00 and sequential and file and format The header that exists in the ISAM .DAT file is ignored during the SEQUENTIAL read. The first READ automatically recovers the first record. PROGRAM1.CBL (shown below) creates an ISAM file. The ISAM key file is called ORIGINAL.IDX and the data file is called ORIGINAL.DAT. PROGRAM2.CBL (also shown below) rebuilds the ISAM file created in PROGRAM1.CBL by sequentially reading data in from ORIGINAL.DAT, then writing the data out to a new ISAM file with the same ORGANIZATION, ACCESS, and FD. The new ISAM key file is called REB.IDX and the data file is called REB.DAT. PROGRAM2.CBL displays information read in from the rebuilt ISAM file REB to show that the information was successfully recovered. Please note that you must OPEN the ORIGINAL.DAT file of the corrupt ISAM file with ORGANIZATION and ACCESS of SEQUENTIAL and you must specify RECORDING MODE IS VARIABLE in the FD section for ORIGINAL.DAT. PROGRAM1.CBL should be compiled and linked as follows: COBOL PROGRAM1; LINK PROGRAM1 + ADIS.OBJ + ADISINIT.OBJ + ADISKEY.OBJ + IXSIO.OBJ; PROGRAM2.CBL should be compiled and linked as follows: COBOL PROGRAM2; LINK PROGRAM2 + ADIS.OBJ + ADISINIT.OBJ + ADISKEY.OBJ + IXSIO.OBJ;

PROGRAM1.CBL
$SET MS(2) IDENTIFICATION DIVISION. PROGRAM-ID. TESTUS. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT CREATE-FILE ASSIGN TO DISK ORGANIZATION IS INDEXED ACCESS IS DYNAMIC RECORD KEY IS PRIME-KEY. DATA DIVISION. FILE SECTION. FD CREATE-FILE LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS &quot;ORIGINAL.DAT&quot;. 01 INPUT-REC. 03 PRIME-KEY     PIC 999. 03 REST-REC      PIC XXX. WORKING-STORAGE SECTION. 01 DISPLAY-STUFF. 03 NUMBERS       PIC 999 VALUE ZERO. 03 LETTERS       PIC XXX VALUE SPACES. 01 ACCUM             PIC 9 VALUE 1. 01 JUNK              PIC X VALUE SPACE. PROCEDURE DIVISION. 000-MAIN. OPEN OUTPUT CREATE-FILE. PERFORM UNTIL ACCUM = 6 DISPLAY &quot;PLEASE ENTER REQUESTED DATA&quot; AT 0220 WITH BLANK SCREEN DISPLAY &quot; TO CREATE AN ISAM FILE: &quot; AT 0320 DISPLAY &quot;Enter a three digit number =>&quot; AT 0505 DISPLAY &quot;Enter three letters       =>&quot; AT 0705 ACCEPT NUMBERS AT 0536 ACCEPT LETTERS AT 0736 MOVE NUMBERS TO PRIME-KEY MOVE LETTERS TO REST-REC WRITE INPUT-REC ADD 1 TO ACCUM. END-PERFORM. CLOSE CREATE-FILE. STOP RUN.

PROGRAM2.CBL
$SET MS(2) IDENTIFICATION DIVISION. PROGRAM-ID. TESTUS. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INP-SEQ ASSIGN TO DISK ORGANIZATION IS SEQUENTIAL ACCESS IS SEQUENTIAL. SELECT REB-FILE ASSIGN TO DISK ORGANIZATION IS INDEXED ACCESS IS DYNAMIC RECORD KEY IS REB-KEY. DATA DIVISION. FILE SECTION. FD  INP-SEQ LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS &quot;ORIGINAL.DAT&quot; RECORDING MODE IS VARIABLE. 01 TEMP-REC. 03   SEQ-KEY     PIC 999. 03   SEQ-REST    PIC XXX. FD REB-FILE LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS &quot;REB.DAT&quot;. 01 REB-REC. 03 REB-KEY   PIC 999. 03 REB-REST  PIC XXX. WORKING-STORAGE SECTION. 01 DISPLAY-STUFF. 03 NUMBERS   PIC 999  VALUE 0. 03 LETTERS   PIC XXX  VALUE SPACES. 01 ACCUM         PIC 9 VALUE 1. 01 JUNK          PIC X VALUE SPACE. 01 MORE-DATA-REMAINS  PIC X VALUE 'Y'. PROCEDURE DIVISION. 000-MAIN. OPEN INPUT INP-SEQ OUTPUT REB-FILE. PERFORM REBUILD-FILE UNTIL MORE-DATA-REMAINS = 'N'. CLOSE INP-SEQ REB-FILE. OPEN INPUT REB-FILE. MOVE 'Y' TO MORE-DATA-REMAINS. PERFORM READ-REBUILT-FILE UNTIL MORE-DATA-REMAINS = 'N'. CLOSE REB-FILE. STOP RUN. REBUILD-FILE. READ INP-SEQ AT END MOVE 'N' TO MORE-DATA-REMAINS. IF MORE-DATA-REMAINS = 'Y'         MOVE SEQ-KEY TO REB-KEY MOVE SEQ-REST TO REB-REST WRITE REB-REC. READ-REBUILT-FILE. READ REB-FILE NEXT RECORD AT END MOVE 'N' TO MORE-DATA-REMAINS. IF MORE-DATA-REMAINS = 'Y'        MOVE REB-KEY TO NUMBERS MOVE REB-REST TO LETTERS DISPLAY &quot;THE CURRENT RECORD IS:&quot; AT 1025 WITH BLANK SCREEN. DISPLAY NUMBERS AT 1335 DISPLAY LETTERS AT 1435 DISPLAY &quot;PRESS RETURN TO SEE THE NEXT RECORD&quot; AT 1820 ACCEPT JUNK AT 0505 ADD 1 TO ACCUM. Copyright Microsoft Corporation 1990.