Reading and writing data - IBM Mainframe

Reading and writing data is an essential part of every program. Your program retrieves information processes it as you specify, and then produces the results you want. The source of the information and the target for the results can be one or more of the following:

  • A direct-access device
  • A magnetic tape
  • A printer
  • A terminal
  • A card reader or punch
  • Another program to which you pass data

The information as it exists on the external device is a physical record or block. It is an actual physical collection of information that is handled as a unit by the system during input/output operations. Your COBOL program does not usually handle these physical records. The information as it is used by your COBOL program is a logical record (which may or may not be the same as the physical record). A logical record can be a complete physical record, it can be part of a physical record, or it can include parts or all of one or more physical records. Your COBOL program handles only these logical records, and it handles them exactly as you have defined them. In COBOL, a collection of physical and logical records is a file; that is, a sequence of pieces of information that your program can process.

Depending on I/O device, your file organization will be sequential, indexed, or relative. You should decide on devices and file types to be used when you design your program. The access methods for input and output available with VS COBOL II are QSAM and VSAM. The terminology differences in file organization are shown in the following table.

COBOL vs. System Terminology

COBOL vs. System Terminology

The general format of input/output coding is shown below. Explanation for user-supplied information (lowercase) is given after the listing.

Identification division

The user-supplied information in the above listing can be explained as follows:

  • filename - Any legal COBOL name. You must use the same filename on the SELECT and the FD statements, and on the READ, OPEN, and CLOSE statements. Additionally, the filename is required if you use the START or DELETE statements. This name is not necessarily the actual name of the data set, as it is known to the system. Each file requires its own SELECT, FD, and I/O statements.
  • assign-name - Any 1- to 30-character name you choose, provided that it follows COBOL and system naming rules. This assignment-name becomes important later, when you get ready to run your program, at which time you specify it on a DD statement.
  • org - Specifies the organization: SEQUENTIAL, INDEXED, or RELATIVE. This clause is optional for QSAM files.
  • ace - Specifies the access mode, SEQUENTIAL, RANDOM, or DYNAMIC. For sequential file processing, you can omit this clause.
  • status - The 2-character COBOL FILE STATUS key.
  • record-name - The tame of the record used in the WRITE and REWRITE statements.
  • Field length - The logical length of the field.
  • type - Must match the file's record format. If you break the record description entry beyond the level-01 description, each element should map accurately against the record's fields.
  • iomode - Specifies INPUT or OUTPUT mode. If you are only reading from a file, specify INPUT. If you are only writing to it, specify OUTPUT or EXTEND. If you are doing both, specify l-O.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

IBM Mainframe Topics