ibmruntimes / vsam.js

Reading and writing vsam files using NodeJS
Apache License 2.0
10 stars 5 forks source link

vsam APIs do not work as expected for multiple records #2

Closed tangthth closed 2 years ago

tangthth commented 6 years ago

Issue Description:

When using vsamObj.find() to find one record in the VSAM data set, it works well. But when using vsamObj.find() to find multiple records, it does not work as expected. Same issue for other vsam APIs like read(), write() etc.

Reproduce Steps:

  1. prepare a VSAM data set of 3 lines.

  2. write a loop like below to find and print each line to the console. <=== no any line could be found or printed. It reports "TypeError: Cannot read property 'key' of null".

  3. change the loop to print only one line, for example: for (var i=0; i<1; i++) <=== each line can be found and printed to console successfully. </u/usra/workdir/nodejs/nodejs.test.vsam_1.0.0/scripts:>node test_vsam.js
    Found record key: 00001, record name: USERNAMEAA, record gender: MESSAGE001 change to: for (var i=1; i<2; i++): </u/usra/workdir/nodejs/nodejs.test.vsam_1.0.0/scripts:>node test_vsam.js
    Found record key: 00002, record name: USERNAMEBB, record gender: MESSAGE002 change to: for (var i=2; i<3; i++): </u/usra/workdir/nodejs/nodejs.test.vsam_1.0.0/scripts:>node test_vsam.js
    Found record key: 00003, record name: USERNAMECC, record gender: MESSAGE003

  4. change the loop to print 2 lines, for example: for (var i=0; i<2; i++) <=== 2 lines could be found but the 1st line is not printed. Instead, the 2nd line is printed twice. </u/usra/workdir/nodejs/nodejs.test.vsam_1.0.0/scripts:>node test_vsam.js
    Found record key: 00002, record name: USERNAMEBB, record gender: MESSAGE002 Found record key: 00002, record name: USERNAMEBB, record gender: MESSAGE002

Logs:

</u/usra/workdir/nodejs/nodejs.test.vsam_1.0.0/scripts:>node test_vsam.js
/u/usra/workdir/nodejs/nodejs.test.vsam_1.0.0/scripts/test_vsam.js:74
assert(record.key, recordkeysÝi¨);
¬
TypeError: Cannot read property 'key' of null
at /u/usra/workdir/nodejs/nodejs.test.vsam_1.0.0/scripts/test_vsam.js:74:18

Reference:

var vsamObj = vsam.openSync(dsname, JSON.parse(fs.readFileSync('schema.json')))
var recordkeys=["00001","00002","00003"]

    for (var i = 0; i < 3; i++) {
        vsamObj.find(recordkeys[i], function(record,err) {
            if (err != null) {
                console.log("Error in finding record by key: " + recordkeys[i])
                        console.error("The Error is: " + err)
            }
            else {
                assert(record.key, recordkeys[i]);
                console.log("Found record key: " + record.key + ", record name: " + record.name + ", record gender: " + record.gender)
            }
        })
    }
gabylb commented 2 years ago

I couldn't reproduce the issue with the current latest vsam.js v3.0.1. Please retry with the latest vsam.js; if you still encounter an issue, please open one.