Skip to content

Instantly share code, notes, and snippets.

@plavjanik
Created April 12, 2019 19:38
Show Gist options
  • Save plavjanik/12f0c95e9bc1281a22977accba1b9895 to your computer and use it in GitHub Desktop.
Save plavjanik/12f0c95e9bc1281a22977accba1b9895 to your computer and use it in GitHub Desktop.
VSAM example
const os = require('os');
const vsam = require('vsam.js');
const vsamDsn = os.userInfo().username + '.TEST.VSAM.KSDS';
const schema = {
key: {
type: "string",
maxLength: 5
},
name: {
type: "string",
maxLength: 10
},
gender: {
type: "string",
maxLength: 10
}
};
var file;
if (!vsam.exist(vsamDsn)) {
console.log(`${vsamDsn} does not exist`);
file = vsam.allocSync(vsamDsn, schema);
console.log(`${vsamDsn} allocated`);
}
else {
file = vsam.openSync(vsamDsn, schema);
}
file.read((record, err) => {
if (record) {
console.log("Record read", record);
file.close((err) => {
console.log("Error", err);
});
} else {
console.log("Creating record");
rec = {
key: "00001",
name: "Petr",
gender: "male"
};
file.write(rec, (err) => {
if (err) {
console.log("Error", err);
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment