开发者

append records to an existing file

If I want to append records to an existi开发者_如何转开发ng file what DISP parameters do I need to use?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜