Previous Topic: VARSIZE()

Next Topic: VVALUE()

VSAM()

Use the VSAM() function to perform I/O operations on VSAM data sets.

Syntax

The VSAM() function has this syntax:

Form 1:

acb = VSAM(OBTAIN,[scope],cbtype)

Form 2:

VSAM(option1,acb)

Form 3:

status = VSAM(STATUS,acb)

Form 4:

VSAM(MODCB,acb,modopt1)

Form 5:

VSAM(MODCB,rpl,modopt2)

Form 6:

dsname = VSAM(DSNAME,acb)

Form 7:

VSAM(POINT,rpl,key)

Form 8:

record = VSAM(act1,rpl,[key])

Form 9:

VSAM(act2,rpl,record)

Form 10:

VSAM(act3,rpl)

Arguments

The VSAM() function takes these arguments:

acb

ID for a VSAM ACB and an associated internal workspace.

OBTAIN

Obtains a new RPL or ACB.

scope

Specify one of these values:

LOCAL

Indicates that the file is local to the IMOD. The RPL or ACB is automatically released at the end of the IMOD.

GLOBAL

Indicates that you can share this file across IMODs. The RPL or ACB must be released explicitly.

Default: LOCAL

cbtype

Specify one of these values:

ACB

Obtains an ACB control block.

RPL

Obtains an RPL control block.

option1

Specify one of these values:

OPEN

Opens a file for processing.

CLOSE

Completes processing.

TCLOSE

Temporarily closes the file. This option writes all information to disk and updates all pointers. However, the file remains open and processing may continue.

RELEASE

Returns handle value to the system to free storage used.

status

Current status of data set (OPEN or CLOSED) as returned by the STATUS operation.

STATUS

Returns the status of the ACB.

MODCB

Modifies the VSAM RPL or ACB.

modopt1

Specify one of these values:

DDNAME=ddname

Modifies the ACB's DDNAME value. Only effective if the data set is currently closed.

MACRF=opt

Modifies the ACB's MACRF values. Choose one or more of the following values, separated by commas: SEQ, OUT, RST, NRS, DIR, KEY, IN. Descriptions of these options can be found in the IBM VSAM reference manuals.

rpl

ID for a VSAM RPL and an associated internal workspace.

modopt2

Specify one of these values:

ACB=acb

Modifies the RPL's ACB value. Before you can use an RPL for operations on a data set, it must be linked to an open ACB.

KEY=key

Modifies the RPL's KEY field. You may set this field directly in the RPL without using the POINT, GET, or DELETE operations.

OPTCD=opt

Modifies the RPL's OPTCD values. Choose one or more of these values, separated by commas: FWD, BWD, SEQ, DIR, KEY, FKS, GEN, UPD, NUP, NSP, KEQ, KGE.

dsname

Data set name of an open data set. This is the cluster name.

DSNAME

Returns the cluster name of an open data set.

POINT

Useful in sequential mode, a POINT operation positions the file to the record that matches key. Subsequent GETs then retrieve records, beginning with the desired one.

key

Key of the desired record. For KSDS processing, the full key or partial key, and the match must be exact or not less than the key value, depending on the processing mode. For RRDS and ESDS processing, key is the numeric relative record number or RBA, respectively.

record

Record text. For keyed records, this includes the key.

act1

Specify one of these values:

GET

Obtains a record. For sequential mode processing, returns next logical record. For direct mode processing, returns record whose key is in the RPL. Direct mode processing permits specification of the key with GET.

DELETE

Deletes the specified record (by key). This is an extension of VSAM functions. Normally, you must first read the record to be erased and then erase it. DELETE eliminates the need to perform the GET.

act2

Specify one of these values:

PUT

Writes a record. Depending upon the update status, a new record is inserted or the current record is replaced. For RRDS and ESDS processing, the key argument is required for a non-update write. For KSDS processing, the key is embedded in the record.

UPDATE

Replaces the specified record (by key). This is an extension of VSAM functions. Normally, you must first read the record to be updated and then replace it. UPDATE eliminates the need to perform the GET. If the record to be updated does not exist, it will be added.

act3

Specify one of these values:

ERASE

In UPDATE mode, causes the last read record to be deleted from the file.

ENDREQ

Terminates any operation in progress on an RPL. For example, if you have read a record for update and then change your mind, you must issue an ENDREQ to free the RPL. Otherwise, you must either update or erase the record to complete the operation.

Return Codes

The VSAM() function produces these return codes:

101 - 104

ARG n MISSING OR INVALID

122

DELETE NOT MATCHED

124

ADD AND UPDATE FOR RECORD BOTH FAILED

126

NOT RPL

127

NO RPL

128

NOT ACB

129

NO ACB

130

DATASET IS OPEN

131

DATASET NOT OPEN

135

PHASE: phase RETURN: ret REASON rea

This is returned for an RPL-based error. phase indicates the failing operations (for example, GET), ret is the value returned in the RPLRET field, and rea is the value returned in the RPL FDBK2 field. These values are explained in detail in the IBM VSAM reference manuals.

136

PHASE: phase R15: ret REASON: rea

This is returned for a non-RPL-based error. phase indicates the failing operation (for example, CLOSE), ret is the value returned (by VSAM) in register 15, and rea is the value returned (by VSAM) in register 0. These values are explained in detail in the IBM VSAM reference manuals.

137

OPEN ERROR. CODE=code

code is the VSAM error code, as explained in the IBM VSAM reference manuals.

Example

/* DDname JUNK was already allocated */
acb = vsam('OBTAIN','ACB') /* Obtain an ACB */
rpl = vsam('OBTAIN','RPL') /* Obtain an RPL */
x   = vsam('MODCB',acb,'DDNAME=JUNK','MACRF=SEQ,DIR,OUT')
                           /* Modify the ACB for the desired
                              file*/
x = vsam('MODCB',rpl,'ACB='||acb)
                           /* Point the RPL back to the ACB */
x = vsam('OPEN',acb)       /* Open the file */
x = vsam('MODCB',rpl,'OPTCD=DIR,FKS,KEQ,UPD')
                           /* Modify the RPL to perform direct
                              I/O,full key,key equal,and fetch
                              for update */
record = vsam('GET',rpl,key)
                           /* Fetch the record that matches the
                              value found in "key" */
record = key||newdata      /* construct new record, retaining the
                              key */
x = vsam('PUT',rpl,record) /* Write the updated record */
x = vsam('CLOSE',acb)      /* Close the file */
                           /* The next two calls are automatic at
                              IMOD end */
vsam('release',acb) == ''  /* Clean up  */
vsam('release',rpl) == ''  /* Clean up  */