Multi-row fetch into data-structure array
The following example reads records from a table 50 rows at a time into a data-structure array:
// The data structure array subfield definitions should match table column definitions
pjs.define("productsp_out", { type: 'data structure', qualified: true, dim: 50, elements: {
"prid": { type: "packed decimal", length: 5, decimals: 0 },
"prname": { type: "char", length: 30 },
"prdesc": { type: "char", length: 60 }
}})
pjs.clear(productsp_out);
var c1 = pjs.allocStmt();
c1.executeDirect("SELECT prid, prname, prdesc FROM demolib/productsp ORDER BY prid");
if (sqlstate == '00000') {
while (c1.hasMoreRows()) {
pjs.fetch(c1, productsp_out, 50);
for (var i = 1; i <= pjs.rowCount(c1); i++) {
console.log({
id: productsp_out[i].prid,
name: productsp_out[i].prname,
desc: productsp_out[i].prdesc
});
}
}
}
c1.close();