files handing
FILE HANDLING
Basic terms
in file handling:
1. Files
2. Records
3. Fields.
4. Physical
file.
4. Logical
files.
FILES: it is collect of records. Ex: student file, employments file.
RECORDS: it is collect of fields that are used
to describe an entity. One or more fields from together are called
records. Ex: student ID, student name.
FIELDS: A set of characters are combined together
called as information.
PHYSICAL FILE: it is the information that exists on
the external device. It is known as external devices.
LOGICAL FILE: it is the information that is used by
the program. In COBOL program one file can be handled at one time only.
Difference between physical and
logical file:
Physical file
|
Logical file
|
1. Occupies the portion of memory. It
contains the original data.
2. It contains 1 record format.
3. Can exist even without logical
file.
4. If there is a logical file for physical
file, the physical file can’t delete until and unless we delete logical file.
|
1. Does not occupy any memory space. Does not contain any data.it loads itself at
run time as per the defined access path.
2. It contains 16 record formats.
3. Can’t exist without physical file.
4. If there is a logical file for a physical
file, the logical file can be deleted without delete the physical file.
.
|
Files are
identified by file name.
Records are
identified by record name.
Fields are
identified by field’s name.
WORKING WITH FILES:
1. Declaration
of files.
2. Processing
of files.
Declaration of
files is done in environment and data division.
Processing of
files is done in procedure division.
Declaration of files:
ENVIRONMENTAL
DIVISION.
INPUT-OUTPUT
SECTION
FILE CONTROL
SELECT LOGICAL FILE NAME ASSIGN
TO PHYSICAL NAME.
ORGANIZATION IS SEQUENTICAL/INDEXED/RELATIVE.
ACCESS MODE IS
SEQUENTICAL/DYNAMIC/RANDOM.
RECORD KEY/RELATIVE KEY IS
----------------------.
FILE STATUS IS FS.
DATA DIVISION.
FILE
SECTION.
FD LOGICIAL
FILE NAME.
01
TR-DATA-FILE.
02 NAME PIC X(09).
WORKING
STORAGE SECTION.
01 WS-FS PIC
X(01).
Processing of files.
STEPS
1. OPEN THE
FILE.
2. LOGICAL
OPERATON LIKE WRITE, READ, REWRITE, UPDATE.
3. CLOSE THE
FILE.
OPENING MODES:
INPUT MODE:
READ (READ DATA FROM THE FILE).
OUTPUT MODE:
WRITE (WRITE THE DATA INTO THE FILE).
INPUT-OUTPUT
MODE: READ AND REWRITE (UPDATE). AND DELETE.
EXTEND MODE:
WRITE (APPEND THE RECORD).
PROCEDURE
DIVISION.
OPEN MODE
LOGICAL FILE NAME.
LOGICAL FOR
WRITE/READ/REWRITE.
CLOSE
LOGICAL FILE.
Comments
Post a Comment