views:

77

answers:

1

Hi,

If I want to append records to an existing file what DISP parameters do I need to use?

+3  A: 

DISP=MOD

This will append to the end of an existing sequential dataset. If the specified dataset does not yet exist, it will be created (in this case DISP=MOD and DISP=NEW are equivalent)

Beware of the following:

Multi-Volume Datasets

Behaviour of DISP=MOD varies depending on whether or not you specify a specific volume. You should review this reference for the rules

Partitioned Datasets

If you specify a member name in the DSNAME parameter, the member name must not already exist. The system positions the read/write mechanism at the end of the data set. If the member name already exists, the system terminates the job.

If you do not specify a member name, the system positions the read/write mechanism at the end of the data set. The system does not make an automatic entry into the directory.

Adding data to the end of a member of a PDS/PDSE is a bit of a trick. You generally have to delete and rewrite the entire member with the new records added to it.

Sequential Datasets and the COBOL OPEN verb

There is some "interplay" between the DISP given in JCL and the COBOL OPEN verb.

If you specify DISP=MOD in your JCL, a COBOL program will add records to the end of a sequential dataset for both OPEN OUTPUT and OPEN EXTEND.

If you specify DISP=OLD in your JCL, a COBOL program will add records to the end of a sequential dataset for OPEN EXTEND. If you open the sequential dataset as OPEN OUTPUT, the original contents of the dataset are deleted and you will effectively be starting with an empty dataset again (just as if you had deleted and reallocated it).

VSAM Datasets

Virtual Storage Access Method (VSAM) files are a whole different kettle of fish. VSAM datasets come in a variety of organizations:

  • KSDS (Key Sequenced Data Set)
  • ESDS (Entry Sequenced Data Set)
  • RRDS (Relative Record Data Set)
  • LSD (Linear Space Data Set)

Each of organization has its own characteristics and usages.

VSAM datasets must be pre-defined before a COBOL program may reference them. This is often done as a separate IDCAMS job. Once the VSAM dataset has been defined, it may accessed through a COBOL (or other) program. This reference provides a good overview for manipulating VSAM datasets under COBOL. The section: Adding records to a VSAM dataset covers the specifics of adding records to a VSAM dataset from a COBOL program. Use the OPEN EXTEND version of the COBOL open statement to add records to the end of an existing ESDS or KSDS VSAM dataset. Note that for KSDS datasets, records must be added in increasing order with respect to the key.

The JCL used to connect a VSAM dataset to program is actually pretty simple, and is described here. Using DISP=MOD is the same as DISP=OLD for existing VSAM datasets (use either one - it makes no difference). Use DISP=SHR if you are not updating the dataset and do not want to block other programs from concurrent access.

NealB
Hi Neal, Thanks for the repy. If I use DISP=MOD then is it like my when I open that file cursor is already positioned at last record?
Manasi
@Manasi Opening a sequential dataset with `DISP=MOD` places the read/write mechanism after the last record in the dataset. The next write issued by your program adds a new record to the dataset (will not overwrite existing records). DISP=MOD implies that you will be writing to the dataset (as opposed to reading from it). Note: The term "cursor" is usually associated with database operations (e.g. cursor position with respect to a multi-row SQL query). For dataset operations we usually refer to the read/write position in the dataset.
NealB
Thanks Neal,If I use DISP=MOD, I have to OPEN file in EXTEND mode , right? Can I use EXTEND with DISP=OLD? If I use DISP=OLD for appending records,where will be my read/write position in dataset?
Manasi
@Manasi. What type of dataset are you dealing with? I assumed it was sequential. Usage of `EXTEND` on the COBOL `OPEN` is often (but not always) associated with VSAM or other organizations. I have added a bit more explanation to my answer - I hope this covers what you are looking for.
NealB
Thanks a lot Neal :)
Manasi