Using data in input and output operations
Define the data that you use in input and output operations
in the FILE SECTION
.
About this task
Provide the following information about the data:
- Name the input and output files that the program will use. Use
the
FD
entry to give names to the files that the input-output statements in thePROCEDURE DIVISION
can refer to.Data items defined in the
FILE SECTION
are not available toPROCEDURE DIVISION
statements until the file has been successfully opened. - In the record description that follows the
FD
entry, describe the fields of the records in the file:- You can code a level-01 description of the entire record, and
then in the
WORKING-STORAGE SECTION
code a working copy that describes the fields of the record in more detail. Use theREAD INTO
statement to bring the records intoWORKING-STORAGE
. Processing occurs on the copy of data inWORKING-STORAGE
. AWRITE FROM
statement writes processed data into the record area defined in theFILE SECTION
. - The record-name established is the object of
WRITE
andREWRITE
statements. - For QSAM files only, you can set the record format in the
RECORDING MODE
clause. If you omit theRECORDING MODE
clause, the compiler determines the record format based on theRECORD
clause and on the level-01 record descriptions. - For QSAM files, you can set a blocking factor for the file in
the
BLOCK CONTAINS
clause. If you omit theBLOCK CONTAINS
clause, the file defaults to unblocked. However, you can override this with z/OS® data management facilities (including aDD
file job-control statement). - For line-sequential files, you can set a blocking factor for the
file in the
BLOCK CONTAINS
clause. When you codeBLOCK CONTAINS 1 RECORDS
, orBLOCK CONTAINS n CHARACTERS
, where n is the length of one logical record in bytes,WRITE
statements result in the record being transferred immediately to the file rather than being buffered. This technique is useful when you want each record written immediately, such as to an error log.
- You can code a level-01 description of the entire record, and
then in the
Programs in the same run unit can share, or have access to, common files. The method for doing this depends on whether the programs are part of a nested (contained) structure or are separately compiled (including programs compiled as part of a batch sequence).
You can
use the EXTERNAL
clause for separately compiled programs.
A file that is defined as EXTERNAL
can be referenced
by any program in the run unit that describes the file.
You can use the GLOBAL
clause
for programs in a nested, or contained, structure. If a program contains
another program (directly or indirectly), both programs can access
a common file by referencing a GLOBAL
file-name.