The INDEXED data have an index layer above the records which is ordered. It is an index tree (B+ tree). The programmer gives a value to the ID field, writes, then the VSAM modifies the index layer, handles or prohibits duplicates, handles deletion and modification.
The VSAM does not let modify the ID value of an existing record. In such case DELETE-WRITE steps are needed.
An INDEXED data acts like a database table, with a primary key.
The index field is usually:
PIC 9(5)
PIC 9(7)
PIC X(10)
PIC X(20)
The alphanumeric values are ordered lexicographically (ABC).
The RELATIVE records has fix, pre-determined number which is handled by the programmer.
The VSAM lets modify the number of an existing record (REWRITE).
The RELATIVE data acts like an array in the storage. Records have fix positions, there is no indexing, ordering.
The programmer finds a record by their number.
The record number can be overwritten therefore in a sequential processing the order will change, while the physical position is staying the same.
Used in systems where the record position has higher priority than the content, or by another word, the content is only metadata.
The record number field is usually:
PIC 9(5)
PIC 9(6)
PIC 9(7)
FIGURE OF STEPS OF ID AND RECORD NUMBER MODIFICATION:
Determination a new ID for a new record:
sequential process (READ until end of file, then increase by 1)
generation of a key and checking whether it is already in use (timestamp, sequence file, counter)
Timestamp:
alphanumerical, YYYYMMDDHHmmSSCC format, PIC X(16)
existence check is necessary (possible ID conflict)
orderable
because in mainframe a lot of access can happen under one timestamp, best practice is to extend it with 2-4 numbers generated randomly (see later)
modern
Sequence file:
numerical
there is a file next to the original file which contains only the next ID number
stabil in case of concurrent programs
classical mainframe solution
Counter:
numerical
good for building new file
ideal at batch load
the counter start at zero, and by writing a new record, the number will be increased by 1
this method can be combined with the sequence file method; after the process, the sequence file can be saved containing the next ID
Random:
numerical
would work if the random number generator of COBOL was undetermenistic, however the algorythm is determenistic (pseudo-random)
works only when the keyspace is huge (e.g. 10^18)
fast, simple
existence check is necessary (higher amount of data cause higher possibility for ID conflict)
not tolerant for concurrent access, better to let 1 program to run on the data
Timestamp + random number:
alphanumerical, YYYYMMDDHHmmSSCCRRR format, PIC X(19)
best practice in modern COBOL
EXAMPLE FOR NEW INDEX GENERATION, SEQUENTIAL METHOD:
EXAMPLE FOR NEW INDEX GENERATION, TIMESTAMP METHOD:
EXAMPLE FOR NEW INDEX GENERATION, SEQUENCE FILE METHOD:
EXAMPLE FOR NEW INDEX GENERATION, RANDOM NUMBER METHOD:
EXAMPLE FOR NEW INDEX GENERATION, TIMESTAMP WITH RANDOM NUMBER METHOD: