| |
 |
|
| |
COBOL TUTORIAL
FOR BCA STUDENTS OF M G UNIVERSITY |
|
| |
|
|
| |
 |
|
| |
|
| |
|
| |
INPUT and OUTPUT verbs are used to read data into
the memory from some input medium and to write the
processed results from the memory onto some output
medium.
|
|
| |
 |
|
| |
|
| |
When
a READ or a WRITE operation is performed on a file,
it must be open. The opening of a file may be done
with the help of the OPEN verb. With the OPEN verb
it must be also indicated whether the file should
be opened as an input file or output file. If it is
an input file, only reading is possible, whereas in
the case of an output file, only writing is possible.
A file once opened remains open until it is closed
by a CLOSE statement.
The OPEN statement in its simple form is as follows:
|
|
| |
 |
|
| |
Example:
|
|
| |
|
|
| |
The example shows that there are two input files named
TRANSACTION and OLDMASTER and one output file called
NEW-MASTER. All these files are opened and these are
ready for reading or writing.
|
|
| |
|
| |
The first OPEN statement opens the MARK-FILE in input
mode and the file is ready for reading. The next statement
makes the RESULT-FILE ready for writing. There may
be several OPEN statements in a program.
|
|
| |
|
| |
|
| |
When the processing of a file is over, the file may
be closed. This is done with the help of the CLOSE-verb.
The form of the CLOSE statement is:
|
|
| |
|
| |
The file must be open when a close statement can be
executed. Once a file is closed, it is no longer available
to the program. It should be opened again if the file
is required subsequently. It may be noted that unlike
the OPEN statement, the nature of the use of the file
(input and output) should not be mentioned in the
CLOSE statement.
Example:
|
|
| |
|
| |
This
statement will close all the four files – TRANSACTION,
OLD-MASTER, NEWMASTER and PRINT-FILE.
|
|
| |
|
|
| |
 |
|
| |
|
|
| |
 |
|
| |
|
|