Monday, November 21, 2011

FILE Statements



READ statement


READ statement is used to read the record from the file.
Syntax:         READ FILENAME [INTO ws-record] [KEY IS FILE-KEY1]
                     [AT END/INVALID KEY imperative statement1]
                   [NOT AT END/NOT INVALID KEY imperative statement2]
                   END-READ
If INTO clause is coded, then the file is directly read into working storage section record. It is preferred as it avoids another move of file-section-record to working-storage-record followed by simple READ. READ-INTO is not preferred for variable size records where the length of the record being read is not known.
KEY IS clause is used while accessing a record randomly using primary/alternate record key.
AT END and NOT AT END are used during sequential READ of the file.
INVALID KEY and NOT INVALID KEY are used during random read of the file.
Before accessing the file randomly, the key field should have a value before READ.

WRITE Statement

Write statement is used to write a new record in the file. If the file is opened in EXTEND mode, the record will be appended. If the file is opened in OUTPUT mode, the record will be added at the current position.

Syntax:         WRITE FILE-RECORD [FROM ws-record]
                     [INVALID KEY imperative statement1]
                   END-WRITE

FROM clause avoids the explicit move of working storage record to file section record before WRITE.

REWRITE Statement

REWRITE is used to update an already read record. To update a record in a file, the file should be opened in I-O mode.
Syntax:         REWRITE FILE-RECORD [FROM ws-record]
                     [INVALID KEY imperative statement1]
                   END-REWRITE

START Statement

START is used with dynamic access mode of indexed files. It establishes the current location in the cluster for READ NEXT statement. START itself does not retrieve any record.
Syntax:         START FILENAME
                     KEY is EQUAL TO/NOT LESS THAN/GREATER THAN key-name
[INVALID KEY imperative statement1]
                   END-START.

DELETE Statement

DELETE is used to delete the most recently read record in the file. To delete a record, the file should be opened in I-O mode.
Syntax:         DELETE FILENAME RECORD
[INVALID KEY imperative statement1]
END-DELETE

No comments:

Post a Comment