Optimizing buffer and device space

Use the APPLY WRITE-ONLY clause to make optimum use of buffer and device space when you create a sequential file with blocked variable-length records.

About this task

With APPLY WRITE-ONLY specified, a buffer is truncated only when the next record does not fit in the unused portion of the buffer. Without APPLY WRITE-ONLY specified, a buffer is truncated when it does not have enough space for a maximum-size record.

The APPLY WRITE-ONLY clause has meaning only for sequential files that have variable-length records and are blocked.

The AWO compiler option applies an implicit APPLY WRITE-ONLY clause to all eligible files. The NOAWO compiler option has no effect on files that have the APPLY WRITE-ONLY clause specified. The APPLY WRITE-ONLY clause takes precedence over the NOAWO compiler option.

There is a record area allocated for file processing. However, due to buffer and device space optimization, the record area may or may not contain the actual record data for processing by the program:
  • The file processing occurs in the record area and the data in the record area can be accessed by the program if one of the following is true:
    • The file is EXTERNAL
    • The file is contained in a "SAME RECORD AREA" statement in the I-O-CONTROL section
    • The program is compiled with the AWO compiler option
  • The file processing typically occurs in a buffer and the data in the record area is not guaranteed to be accessible by the program (storage undefined) if all of the following is true:
    • The file is not EXTERNAL
    • The file is not contained in a "SAME RECORD AREA" statement in the I-O-CONTROL section
    • The program is compiled with the NOAWO compiler option
Therefore, programs should not reference data directly in the file's record area. Instead, when a file record is read in, it should be read into a data item defined in WORKING-STORAGE or if read into the record area, should be immediately moved to a data item in WORKING-STORAGE for use by the program. For example:

FD  MY-INPUT-FILE
   LABEL RECORDS ARE STANDARD
   RECORDING MODE IS V
   BLOCK CONTAINS 0 RECORDS
   DATA RECORD IS IN-RECORD-AREA.
01 IN-RECORD-AREA     PIC X(100).

WORKING-STORAGE.
01 WS-IN-RECORD-AREA  PIC X(100).

PROCEDURE DIVISION.
...
READ MY-INPUT-FILE INTO WS-IN-RECORD-AREA.

Related references  
AWO