Microsoft KB Archive/32951

Sequential (Variable-Length) File Format in COBOL 3.x, 4.x

PSS ID Number: Q32951 Article last modified on 04-21-1993

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

Summary: The article below describes the format of variable-length-record SEQUENTIAL files in Microsoft COBOL Versions 3.0, 3.0a, 4.0, and 4.5. (This format differs from SEQUENTIAL access file format in earlier versions of Microsoft COBOL.) Note that fixed-length-record SEQUENTIAL files are the default in COBOL 3.0, 3.0a, 4.0, and 4.5. To get variable-length-record SEQUENTIAL files, you must use the RECORDING MODE IS VARIABLE clause in the file FD, or the RECMODE(V) compiler directive, or the RECORD IS VARYING IN SIZE… DEPENDING ON clause in the FD.

More Information: [The SEQUENTIAL file format described below is the same format as for the .DAT data file portion of an ISAM file. If your ISAM index (.IDX) file is corrupted, you can read the .DAT file with ORGANIZATION SEQUENTIAL ACCESS SEQUENTIAL and RECORDING MODE IS VARIABLE, and attempt to rebuild it, as mentioned on Page 7-17 of the “Microsoft COBOL Compiler Version 3.0: Operating Guide.”] There is a 128-byte header record at the beginning of each variable-length-record SEQUENTIAL file. The 128-byte header is followed by the records that make up the file. Each record is preceded by one “status” byte and a length-specification field (1 or 3 bytes), as explained below: 1. Record status byte: The first 4 bits of the status byte specify the record status as follows: 0100 = valid record Any other value indicates that the record is not in use or is a system record. The remaining 4 bits of the status byte are unused. 2. Record length-specification field (LSF) 1 or 3 bytes in length, depending on maximum record size: If the file’s maximum record size <= 4096 bytes, then LSF is 1 byte. If the file’s maximum record size > 4096 bytes, then LSF is 3 bytes. Each record (including the status-byte field and length field) is aligned on a 4-byte boundary.

SEQUENTIAL File Format Example
Take a variable-length record SEQUENTIAL file that contains two record types: one can be 80 characters, and the other can be 30 characters. Write 80 characters of “A” for the first record and 30 characters of “B” to the second record. If examined with DEBUG (or another file utility) starting at location 80 hex, you see the following hex values for each byte: 40 50 41 41. . . (repeated for 80 characters) | | |–| Status | | field | ASCII hex code for the character “A” | Length Specification Field The above record would be padded with 2 space characters to align the record on a 4-byte boundary. (Status field + length field + 80 characters of data = 82 characters. Add 2 spaces to bring total to 84 bytes.) For the second record, you see the following: 40 1E 42 42. . . (repeated for 30 characters) | | |–| Status | | field | ASCII hex code for the character “B” | Length Specification Field

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