Explain the Various Types of Input and Output Verbs

Types of Input and Output Verbs in COBOL

A statement always start with a COBOL verb. It used in the procedure division for data processing. COBOL utilizes specific verbs for handling input and output operations, which can be broadly categorized into two types:

1. Basic Screen Input/Output Verbs

The basic screen input/output verbs in COBOL are ACCEPT and DISPLAY. These verbs facilitate interaction with the user’s terminal or the operating system.

  • ACCEPT Verb: The ACCEPT verb is used to obtain input from the user or retrieve system information like date, time, or day. When accepting input from a user, the program typically waits for the user to enter data and press Enter. When retrieving system information, a FROM clause is used to specify the source.
  • DISPLAY Verb: The DISPLAY verb is used to show output on the user’s screen or console. It can display literals or the contents of data items.

2. File Handling Verbs

COBOL utilizes specific verbs for handling files and performing input/output operations. These verbs are used to interact with external data files (sequential, indexed, or relative).

  • OPEN: This verb makes a file available for processing. It must be the first operation performed on a file. Files can be opened in various modes.
  • CLOSE: This verb closes the file, making it unavailable for further operations and releasing system resources.
  • READ: This verb retrieves one record at a time from a file. It is used when the file has been opened in INPUT or I-O mode.
  • WRITE: This verb writes a record to a file. It is used when the file has been opened in OUTPUT or EXTEND mode.
  • REWRITE: This verb updates an existing record in a file. It requires the file to be opened in I-O mode and a record to have been previously read from the file.
  • START: This verb positions the file pointer to a specific record in an indexed or relative file, based on a key value. It is used to begin sequential processing from a particular point or to access a specific record directly.
  • DELETE: This verb removes a record from an indexed or relative file. It requires the file to be opened in I-O mode and a record to have been previously read or located using the START verb.