Processing existing files

When your program processes an existing file, code the description of the file in your COBOL program to be consistent with the file attributes of the data set. Use the guidelines below to define the maximum record length.

Table 1. Maximum record length of QSAM files
For this format: Specify this:
V or S Exactly 4 bytes less than the length attribute of the data set
F Same value as the length attribute of the data set
U Same value as the length attribute of the data set

The easiest way to define variable-length (format-V) records in a program is to use the RECORD IS VARYING FROM integer-1 TO integer-2 clause in the FD entry and set an appropriate value for integer-2. Express the integer sizes in bytes regardless of the underlying USAGE of the data items in the record. For example, assume that you determine that the length attribute of the data set is 104 bytes (LRECL=104). Remembering that the maximum record length is determined from the RECORD IS VARYING clause and not from the level-01 record descriptions, you could define a format-V file in your program with this code:


FILE SECTION.
FD  COMMUTER-FILE-MST
    RECORDING MODE IS V
    RECORD IS VARYING FROM 4 TO 100 CHARACTERS.
01  COMMUTER-RECORD-A   PIC X(4).
01  COMMUTER-RECORD-B   PIC X(75).

Assume that the existing file in the previous example was format-U instead of format-V. If the 104 bytes are all user data, you could define the file in your program with this code:


FILE SECTION.
FD  COMMUTER-FILE-MST
    RECORDING MODE IS U
    RECORD IS VARYING FROM 4 TO 104 CHARACTERS.
01  COMMUTER-RECORD-A   PIC X(4).
01  COMMUTER-RECORD-B   PIC X(75).

To define fixed-length records in your program, either code the RECORD CONTAINS integer clause, or omit this clause and code all level-01 record descriptions to be the same fixed size. In either case, use a value that equals the value of the length attribute of the data set. If you intend to use the same program to process different files at run time, and those files have differing fixed lengths, avoid record-length conflicts by coding RECORD CONTAINS 0.

If the existing file is an ASCII data set (DCB=(OPTCD=Q)), you must use the CODE-SET clause in the FD entry for the file.

related references  
FILE SECTION entries