|
HP COBOL Reference Manual
Indexed Files
- The file must be open in the OUTPUT, I-O, or EXTEND mode when the
WRITE statement executes. (See Table 6-15.)
- Executing a Format 2 WRITE statement releases a record to the I-O
system. The contents of the record keys enable later record access
based on any defined key.
- When the file description entry has a RECORD KEY IS clause, the
prime record key value is unique unless the DUPLICATES phrase is
specified. When a program later accesses these records sequentially,
the retrieval order is the same as the order in which they were written
in the program.
- The program must set the value of the prime record key data item
before executing the WRITE statement.
- If the file is open in the sequential access mode, the program must
release records in ascending or descending order of prime record key
values, depending on the sort order specified in the RECORD KEY clause.
If the file is open in the extend mode, the first released record must
have a prime record key value that logically follows the last record in
the file according to the prime key sort order.
- If the file is open in the random or dynamic access mode, the
program can release records in any order.
- When the file description entry has an ALTERNATE RECORD KEY clause,
the alternate record key value is unique unless the program specifies
the DUPLICATES phrase. When a program later accesses these records
sequentially, the retrieval order is the same as the order in which
they were written in the program.
- The invalid key condition occurs for any of the following:
- The file is open in the sequential access mode and in the
OUTPUT or EXTEND mode, and the prime record key value does not
logically follow the prime record key value of the previous record.
- The file is open in the OUTPUT, EXTEND, or I-O mode, the prime
record key value duplicates an existing record's prime record key
value, and the program does not specify duplicates on the prime record
key.
- The file is open in the OUTPUT, EXTEND, or I-O mode, and the value
of an alternate record key (for which duplicates are not allowed)
duplicates the value of the corresponding data item in an existing
record.
- The program tries to write a record beyond the externally defined
file boundaries.
- When the program detects an invalid key condition, WRITE statement
execution is unsuccessful. The following results occur:
- The contents of the current record area are not affected.
- The WRITE statement sets the FILE STATUS data item for the file to
indicate the cause of the condition.
- Program execution continues according to the rules for the invalid
key condition.
See the rules for the INVALID KEY phrase,
Section 6.6.10.
Technical Notes
- WRITE statement execution can result in these FILE STATUS data item
values:
File Status |
File Organization |
Access Method |
Meaning |
00
|
All
|
All
|
Write is successful
|
02
|
Ind
|
All
|
Created duplicate primary or alternate key
|
21
|
Ind
|
Seq
|
Attempted key value not in prime key sort order (invalid key)
|
22
|
Ind, Rel
|
All
|
Duplicate key (invalid key)
|
24
|
Ind, Rel
|
All
|
Boundary violation (relative or indexed files) or relative record
number is too large for relative key data item (invalid key)
|
34
|
Seq
|
Seq
|
Boundary violation (sequential files)
|
44
|
All
|
All
|
Boundary violation. An attempt was made to write a record that is
larger than the largest or smaller than the smallest record allowed
|
48
|
All
|
All
|
File not open, or incompatible open mode
|
92
|
Ind, Rel
|
All
|
Record locked by another process
|
30
|
All
|
All
|
All other permanent errors
|
In order to detect "device full" (file status 34) on a sequential WRITE
operation, each WRITE needs to be followed by a call to SYS$FLUSH to
ensure that an attempt has been made to write any buffered records to
disk. For more information, at the OpenVMS system prompt, type
Additional References
6.9 END PROGRAM Header
Function
The END PROGRAM header indicates the end of the named COBOL source
program. Alternatively, the end of a named COBOL source program can be
indicated by the end of the program's Procedure Division.
program-name
must contain 1 to 31 characters and follow the rules for user-defined
words. It must be identical to a program-name declared in a preceding
PROGRAM-ID paragraph.
Syntax Rules
- An inside PROGRAM-ID/END PROGRAM pair must be contained within the
outside pair.
- The END PROGRAM header must be present in every program that either
contains or is contained within another program.
- The END PROGRAM header indicates the end of a specific COBOL source
program.
- The END PROGRAM header starts in Area A.
- The only COBOL statements that can follow an END PROGRAM header are
as follows:
- An Identification Division header of another program
- Another END PROGRAM header
The last END PROGRAM header must reference the outermost containing
program.
- If a program includes an END PROGRAM header and if it is not
contained in another program, the next COBOL statement, if any, must be
the Identification Division header of another program to be compiled.
Additional Reference
Section 3.1.1 paragraph in Chapter 3
Examples
- This separately compiled program (PROG-NAME-A) (1)
contains one program (PROG-NAME-B) (2).
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG-NAME-A. (1)
PROCEDURE DIVISION.
...
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG-NAME-B. (2)
PROCEDURE DIVISION.
...
END PROGRAM PROG-NAME-B.
END PROGRAM PROG-NAME-A.
|
- This separately compiled program (PROG-NAME-A) (4)
contains eight other programs (5) through
(12). Also, (6) is contained within
(5), and (7) is contained within
(6). (9), (10), and
(11) are contained within (8).
(5), (8), and (12) are directly
contained within (4).
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG-NAME-A. (4)
...
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG-NAME-B. (5)
...
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG-NAME-C. (6)
...
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG-NAME-D. (7)
...
END PROGRAM PROG-NAME-D.
END PROGRAM PROG-NAME-C.
END PROGRAM PROG-NAME-B.
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG-NAME-F. (8)
...
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG-NAME-G. (9)
...
END PROGRAM PROG-NAME-G.
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG-NAME-H. (10)
...
END PROGRAM PROG-NAME-H.
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG-NAME-I. (11)
...
END PROGRAM PROG-NAME-I.
END PROGRAM PROG-NAME-F.
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG-NAME-J. (12)
...
END PROGRAM PROG-NAME-J.
END PROGRAM PROG-NAME-A.
|
|