IBM - VisualAge Cobol for Windows Programming Guide
634 pág.

IBM - VisualAge Cobol for Windows Programming Guide


DisciplinaCobol25 materiais168 seguidores
Pré-visualização50 páginas
or OPEN EXTEND.
If you open a sequential, line-sequential, or relative file as EXTEND, the added
records are placed after the last existing record in the file. If you open an indexed
file as EXTEND, each record you add must have a record key higher than the highest
record in the file.
RELATED CONCEPTS
\u201cFile organization and access mode\u201d on page 100
RELATED TASKS
\u201cProtecting against errors when opening files\u201d on page 100
RELATED REFERENCES
\u201cValid COBOL statements for sequential files\u201d
\u201cValid COBOL statements for line-sequential files\u201d on page 108
\u201cValid COBOL statements for indexed and relative files\u201d on page 108
OPEN statement (IBM COBOL Language Reference)
Valid COBOL statements for sequential files
The following table shows the possible combinations of input-output statements
for sequential files. The \u2019X\u2019 indicates that the statement can be used with the open
mode given at the top of the column.
Access mode COBOL statement
OPEN
INPUT
OPEN
OUTPUT
OPEN
I-O
OPEN
EXTEND
Sequential OPEN X X X X
WRITE X X
START
READ X X
REWRITE X
DELETE
CLOSE X X X X
Chapter 7. Processing files 107
RELATED CONCEPTS
\u201cSequential file organization\u201d on page 101
\u201cSequential access\u201d on page 102
Valid COBOL statements for line-sequential files
The following table shows the possible combinations of input-output statements
for line-sequential files. The \u2019X\u2019 indicates that the statement can be used with the
open mode given at the top of the column.
Access mode COBOL statement
OPEN
INPUT
OPEN
OUTPUT
OPEN
I-O
OPEN
EXTEND
Sequential OPEN X X X
WRITE X X
START
READ X
REWRITE
DELETE
CLOSE X X X
RELATED CONCEPTS
\u201cLine-sequential file organization\u201d on page 101
\u201cSequential access\u201d on page 102
Valid COBOL statements for indexed and relative files
The following table shows the possible combinations of input-output statements
for indexed and relative files. The \u2019X\u2019 indicates that the statement can be used with
the open mode given at the top of the column.
Access mode COBOL statement
OPEN
INPUT
OPEN
OUTPUT
OPEN
I-O
OPEN
EXTEND
Sequential OPEN X X X X
WRITE X X
START X X
READ X X
REWRITE X
DELETE X
CLOSE X X X X
Random OPEN X X X
WRITE X X
START
READ X X
REWRITE X
DELETE X
CLOSE X X X
108 Programming Guide
Access mode COBOL statement
OPEN
INPUT
OPEN
OUTPUT
OPEN
I-O
OPEN
EXTEND
Dynamic OPEN X X X
WRITE X X
START X X
READ X X
REWRITE X
DELETE X
CLOSE X X X
RELATED CONCEPTS
\u201cIndexed file organization\u201d on page 101
\u201cRelative file organization\u201d on page 102
\u201cSequential access\u201d on page 102
\u201cRandom access\u201d on page 102
\u201cDynamic access\u201d on page 103
Reading records from a file
Use the READ statement to retrieve (read) records from a file. To read a record, you
must have opened the file with OPEN INPUT or OPEN I-O (OPEN I-O is not valid for
line-sequential files). Check the file status key after each READ.
Records in sequential and line-sequential files can be retrieved only in the
sequence in which they were written.
Records in indexed and relative record files can be retrieved sequentially
(according to the ascending order of the key you are using for indexed files, or
according to ascending relative record locations for relative files), randomly, or
dynamically.
With dynamic access, you can switch between reading a specific record directly
and reading records sequentially, by using READ NEXT and READ PREVIOUS for
sequential retrieval, and READ for random retrieval (by key).
When you want to read sequentially beginning at a specific record, use START
before the READ NEXT or the READ PREVIOUS statements to set the file position
indicator to point to a particular record. When you code START followed by READ
NEXT, the next record is read and the file position indicator is reset to the next
record. When you code START followed by READ PREVIOUS, the previous record is
read and the file position indicator is reset to the previous record. You can move
the file position indicator randomly by using START, but all reading is done
sequentially from that point.
You can continue to read records sequentially, or you can use the START statement
to move the file position indicator. For example:
START file-name KEY IS EQUAL TO ALTERNATE-RECORD-KEY
When a direct READ is performed for an indexed file based on an alternate index
for which duplicates exist, only the first record in the file (base cluster) with that
alternate key value is retrieved. You need a series of READ NEXT statements to
retrieve each of the data set records with the same alternate key. A FILE STATUS
Chapter 7. Processing files 109
value of 02 is returned if there are more records with the same alternate key value
to be read. A value of 00 is returned when the last record with that key value has
been read.
RELATED CONCEPTS
\u201cSequential access\u201d on page 102
\u201cRandom access\u201d on page 102
\u201cDynamic access\u201d on page 103
\u201cFile organization and access mode\u201d on page 100
RELATED TASKS
\u201cOpening a file\u201d on page 107
\u201cUsing file status keys\u201d on page 129
RELATED REFERENCES
\u201cFile position indicator\u201d on page 106
FILE STATUS clause (IBM COBOL Language Reference)
Statements used when writing records to a file
The following table shows the COBOL statements that you can use when creating
or extending a file.
Division Sequential Line sequential Indexed Relative
ENVIRONMENT SELECT
ASSIGN
FILE STATUS
ACCESS MODE
SELECT
ASSIGN
ORGANIZATION
IS LINE SEQUENTIAL
FILE STATUS
ACCESS MODE
SELECT
ASSIGN
ORGANIZATION
IS INDEXED
RECORD KEY
ALTERNATE
RECORD KEY
FILE STATUS
ACCESS MODE
SELECT
ASSIGN
ORGANIZATION
IS RELATIVE
RELATIVE KEY
FILE STATUS
ACCESS MODE
DATA FD entry FD entry FD entry FD entry
PROCEDURE OPEN OUTPUT
OPEN EXTEND
WRITE
CLOSE
OPEN OUTPUT
OPEN EXTEND
WRITE
CLOSE
OPEN OUTPUT
OPEN EXTEND
WRITE
CLOSE
OPEN OUTPUT
OPEN EXTEND
WRITE
CLOSE
RELATED CONCEPTS
\u201cFile organization and access mode\u201d on page 100
RELATED TASKS
\u201cSpecifying a file organization and access mode\u201d on page 100
\u201cOpening a file\u201d on page 107
\u201cSetting up a field for file status\u201d on page 104
\u201cAdding records to a file\u201d
RELATED REFERENCES
\u201cPROCEDURE DIVISION statements used to update files\u201d on page 112
Adding records to a file
The COBOL WRITE statement adds a record to a file without replacing any existing
records. The record to be added must not be larger than the maximum record size
set when the file was defined. Check the file status key after each WRITE statement.
110 Programming Guide
Adding records sequentially
Use ACCESS IS SEQUENTIAL and code the WRITE statement to add records
sequentially to the end of a file that has been opened with either OUTPUT or EXTEND.
Sequential and line-sequential files are always written sequentially.
For indexed files, new records must be written in ascending key sequence. If the
file is opened EXTEND, the record keys of the records to be added must be higher
than the highest primary record key in the file when the file was opened.
For relative files, the records must be in sequence. If you include a RELATIVE KEY
data item in the SELECT clause, the relative record number of the record to be
written is placed in that data item.
Adding records randomly or dynamically
When you write records to an indexed data set for which you have coded ACCESS
IS RANDOM or ACCESS IS DYNAMIC, the records can be written in any order.
RELATED CONCEPTS
\u201cFile organization and access mode\u201d on page 100
RELATED TASKS
\u201cSpecifying a file organization and access mode\u201d on page 100
\u201cUsing file status keys\u201d on page 129
RELATED REFERENCES
\u201cStatements used when writing records to a file\u201d on page 110
\u201cPROCEDURE DIVISION statements used to update files\u201d on page 112
FILE STATUS clause (IBM