Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


The following example selects reads records from a file table 50 rows at a time , into a data-structure array.:

Code Block
languagejavascript
// 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, initValue: 105 },
    "prname": { type: "char", length: 30 },
    "prdesc": { type: "char", length: 60 }
  }})

  pjs.connect("*LOCAL");
 


pjs.clear(productsp_out);

  var c1 = pjs.allocStmt();
  pjsc1.executeDirect(c1, "selectSELECT prid, prname, prdesc fromFROM demolib/productsp orderORDER byBY prid", "c1");

  if (SQLSTATEsqlstate == '00000') {

  while (c1.hasMoreRows()) {
    pjs.fetch(c1, productsp_out, 50);
     if (SQLSTATE == '00000') {
      //SQLERRD[3] = count of rows returned
      for (var i = 1; i <= SQLERRD[3]pjs.rowCount(c1); i++) {

       console.log({ 
 
        id: productsp_out[i].prid, 
          name: productsp_out[i].prname, 
          desc: productsp_out[i].prdesc 
        });
 
    }
 
  }


 }

  pjsc1.close(c1);