Microsoft KB Archive/47890

65,536 DUPLICATE ALTERNATE Keys Overwrites Last ISAM Record PSS ID Number: Q47890 Article last modified on 04-20-1993

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

Summary: Writing an ISAM file with more than 65,536 DUPLICATES in an ALTERNATE KEY produces incorrect results with Microsoft COBOL Compiler versions 3.0 and 3.0a. Each record written after those 65,536 will overwrite the last record in the file. Thus, any record written to the file after 65,536 DUPLICATES have occurred will be lost. Microsoft has confirmed this to be a problem in COBOL versions 3.0 and 3.0a for MS-DOS and MS OS/2. This problem has also been confirmed in Microsoft COBOL Professional Development System version 4.0. We are researching this problem and will post new information as it becomes available.

More Information: This problem does not affect the FILE STATUS key variable and cannot be detected by checking the FILE STATUS key. The problem becomes apparent only when an attempt is made to read or rebuild the file after data has been lost. A workaround is to change or remove the ALTERNATE KEYs so that each occurrence has fewer than 65,536 DUPLICATES.

Code Example
The following code example attempts to write 100,000 records. However, because the ALTERNATE KEYs are all DUPLICATES, after 65,536 records have been written, the last record will be continually overwritten. Only 65,536 records will be retained. After the program finishes, the RECORD KEY position in the records in ALTKEY.DAT will contain “000001A” to “065535A” in the first 65,535 records and “100000A” in the last record. However, the records with a primary key of “065536A” to “099999A” will not be in the file, even though they were written and no error was encountered. * COMPILE LINE: * COBOL TESTPROG.COB; * LINK LINE: * LINK TESTPROG IXSIO; ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT OUTPUT-FILE ASSIGN TO DISK ORGANIZATION IS INDEXED ACCESS IS SEQUENTIAL RECORD KEY IS PRIME-KEY ALTERNATE KEY IS ALT-KEY DUPLICATES FILE STATUS IS FILE-STAT. DATA DIVISION. FILE SECTION. FD OUTPUT-FILE LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS “ALTKEY.DAT”. 01 OUTPUT-REC. 02 PRIME-KEY PIC 9(6). 02 ALT-KEY PIC X(1). WORKING-STORAGE SECTION. 01 OUTPUT-DATA. 02 PRIME-DATA PIC 9(6). 02 ALT-DATA PIC X(1) VALUE “A”. 77 FILE-STAT PIC XX. PROCEDURE DIVISION. 000-MAIN. OPEN OUTPUT OUTPUT-FILE. PERFORM WRITE-BATCH 100 TIMES. CLOSE OUTPUT-FILE. STOP RUN. WRITE-BATCH. PERFORM WRITE-ONE 1000 TIMES. DISPLAY PRIME-KEY. WRITE-ONE. ADD 1 TO PRIME-DATA. MOVE OUTPUT-DATA TO OUTPUT-REC. WRITE OUTPUT-REC.

Additional reference words: 3.00 3.00a 4.00 Copyright Microsoft Corporation 1993.