This NodeJS module enables you to read and modify VSAM datasets on z/OS
Before installing, download and install Node.js. Node.js 6.11.4 or higher is required.
Vsam.js is designed to be a bare bones vsam I/O module.
if (vsam.exist("sample.test.vsam.ksds"))
dataset = vsam.openSync("sample.test.vsam.ksds",
JSON.parse(fs.readFileSync('schema.json')));
dataset.find("0321", (record, err) => {
if (err != null)
console.log("Not found!");
else {
assert(record.key, "0321");
console.log(`Current details: Name(${record.name}), Gender(${record.gender})`);
record.name = "KEVIN";
dataset.update(record, (err) => {
dataset.close();
});
}
}
);
schema.json looks like this:
{
"key": {
"type": "string",
"maxLength": 5
},
"name": {
"type": "string",
"maxLength": 10
},
"gender": {
"type": "string",
"maxLength": 10
}
}
- Opening a vsam dataset for I/O
- Allocating a vsam dataset for I/O
- Check if vsam dataset exists
- Closing a vsam dataset
- Reading a record from a vsam dataset
- Writing a record to a vsam dataset
- Finding a record in a vsam dataset
- Updating a record in a vsam dataset
- Deleting a record from a vsam dataset
- Deallocating a vsam dataset
const vsam = require('vsam');
const fs = require('fs');
var vsamObj = vsam.allocSync("VSAM.DATASET.NAME", JSON.parse(fs.readFileSync('schema.json')));
- The first argument is the VSAM dataset name to allocate.
- The second argument is the JSON object derived from the schema file.
- The value returned is a vsam dataset handle. The rest of this readme describes the operations that can be performed on this object.
- Usage notes:
- If the dataset already exists, this function will throw an exception.
- On any error, this function with throw an exception.
const vsam = require('vsam');
const fs = require('fs');
var vsamObj = vsam.openSync("VSAM.DATASET.NAME", JSON.parse(fs.readFileSync('schema.json')));
- The first argument is the name of an existing VSAM dataset.
- The second argument is the JSON object derived from the schema file.
- The value returned is a vsam dataset handle. The rest of this readme describes the operations that can be performed on this object.
- Usage notes:
- On error, this function with throw an exception.
const vsam = require('vsam');
const fs = require('fs');
if (vsam.exist("VSAM.DATASET.NAME")) {
/* Open the vsam file. */
}
- The first argument is the name of an existing VSAM dataset.
- Boolean value is returned indicating whether dataset exists or not.
vsamObj.close((err) => { /* Handle error. */ });
- The first argument is a callback function containing an error object if the close operation failed.
vsamObj.read((record, err) => {
/* Use the record object. */
});
- The first argument is a callback function whose arguments are as follows:
- The first argument is an object that contains the information from the read record.
- The second argument will contain an error object in case the read operation failed.
- Usage notes:
- The read operation retrievs the record under the current cursor and advances the cursor by one record length.
vsamObj.write(record, (err) => {
/* Make sure err is null. */
});
- The first argument is record object that will be written.
- The second argument is a callback to notify of any error in case the write operation failed.
- Usage notes:
- The write operation advances the cursor by one record length after the newly written record.
- The write operation will overwrite any existing record with the same key.
vsamObj.find(recordKey, (record, err) => {
/* Use record information. */
});
- The first argument is record key (usually a string).
- The second argument is a callback
- The first argument is a record object retrieved using the key provided.
- The second argument is an error object in case the operation failed.
- Usage notes:
- The find operation will place the cursor at the queried record (if found).
- The record object in the callback will by null if the query failed to retrieve a record.
vsamObj.update(record, (err) => {
...
});
- The first argument is record object.
- The second argument is a callback
- The first argument is an error object in case the operation failed.
- Usage notes:
- The update operation will write over the record currently under the cursor.
vsamObj.delete((err) => { /* Handle error. */ });
- The first argument is a callback function containing an error object if the delete operation failed.
- Usage notes:
- The record under the current position of the dataset cursor gets deleted.
- This will usually be placed inside the callback of a find operation. The find operation places the cursor on the desired record and the subsequent delete operation deletes it.
vsamObj.dealloc((err) => { /* Handle error. */ });
- The first argument is a callback function containing an error object if the deallocation operation failed.