diff --git a/lib/itoolkit.js b/lib/itoolkit.js
index 594b2135..d78c9634 100644
--- a/lib/itoolkit.js
+++ b/lib/itoolkit.js
@@ -347,11 +347,9 @@ class iPgm {
opt = type;
else
opt = options;
+
if(!inDs) { // In recursive mode, if it is an element in DS, then no or needed.
- if(opt && opt.io)
- this.xml += i_xml.iXmlNodeParmOpen(opt.io);
- else
- this.xml += i_xml.iXmlNodeParmOpen();
+ this.xml += i_xml.iXmlNodeParmOpen(opt);
}
if(__getClass(data) == "Array") { // If it is a struct parameter, recursivly parse its children.
if(opt)
diff --git a/lib/ixml.js b/lib/ixml.js
index 0a93a318..face22ff 100644
--- a/lib/ixml.js
+++ b/lib/ixml.js
@@ -107,6 +107,7 @@ const I_XML_ATTR_KEY_DB = "db";
const I_XML_ATTR_KEY_USERID = "uid";
const I_XML_ATTR_KEY_PASSWORD = "pwd";
const I_XML_ATTR_KEY_IO = "io";
+const I_XML_ATTR_KEY_BY = "by";
const I_XML_ATTR_VALUE_IO = "both";
const I_XML_ATTR_KEY_OFFSET = "offset";
const I_XML_ATTR_KEY_TOP = "top";
@@ -173,9 +174,21 @@ const iXmlNodePgmClose = () => {
return I_XML_NODE_PGM_CLOSE;
}
-const iXmlNodeParmOpen = (xio) => {
+const iXmlNodeParmOpen = (opt) => {
+ if (!(opt && typeof opt==='object')){
+ return iXmlNodeOpen(I_XML_NODE_PARM_OPEN)
+ + I_XML_NODE_CLOSE;
+ }
+
+ let opt_io=(opt.io) ? iXmlAttrDefault(I_XML_ATTR_KEY_IO,opt.io,I_XML_ATTR_VALUE_OPTIONAL) : "";
+ let opt_by=(opt.by) ? iXmlAttrDefault(I_XML_ATTR_KEY_BY,opt.by,I_XML_ATTR_VALUE_OPTIONAL) : "";
+
+ delete opt.by;
+ delete opt.io;
+
return iXmlNodeOpen(I_XML_NODE_PARM_OPEN)
- + iXmlAttrDefault(I_XML_ATTR_KEY_IO,xio,I_XML_ATTR_VALUE_OPTIONAL)
+ + opt_io
+ + opt_by
+ I_XML_NODE_CLOSE;
}
diff --git a/test/unit/iPgmUnit.js b/test/unit/iPgmUnit.js
index 81d534b6..15508a89 100644
--- a/test/unit/iPgmUnit.js
+++ b/test/unit/iPgmUnit.js
@@ -133,6 +133,58 @@ describe('iPgm Class Unit Tests', () => {
expect(pgm.toXML()).to.equal(expectedXML);
});
+
+ it('regular contains by=\'val\'', () => {
+ const pgm = new iPgm("MYPGM", {lib:"MYLIB", func: "MY_PROCEDURE"});
+
+ pgm.addParam("", "1A", {by:"val"});
+ pgm.addReturn("", "2A", {name:"output"});
+
+ let lookAtXML=pgm.toXML();
+ expect(lookAtXML).to.match(//);
+ });
+
+ it('data structure contains by=\'val\'', () => {
+ const pgm = new iPgm("MYPGM", {lib:"MYLIB", func: "MY_PROCEDURE"});
+
+ const p_inds=[
+ [0, "3s0"],
+ [0, "7s0", {name:"ds_fld2"}]
+ ];
+
+ pgm.addParam(p_inds, {name:"inds", by:"val"});
+ pgm.addReturn("", "2A", {name:"output"});
+
+ let lookAtXML=pgm.toXML();
+ expect(lookAtXML).to.match(//);
+ });
+
+ it('regular contains by=\'val\', with io=\'both\'', () => {
+ const pgm = new iPgm("MYPGM", {lib:"MYLIB", func: "MY_PROCEDURE"});
+
+ pgm.addParam("", "1A", {by:"val", io:"both"});
+ pgm.addReturn("", "2A", {name:"output"});
+
+ let lookAtXML=pgm.toXML();
+ expect(lookAtXML).to.match(//);
+ expect(lookAtXML).to.match(//);
+ });
+
+ it('data structure contains by=\'val\', with io=\'both\'', () => {
+ const pgm = new iPgm("MYPGM", {lib:"MYLIB", func: "MY_PROCEDURE"});
+
+ const p_inds=[
+ [0, "3s0"],
+ [0, "7s0", {name:"ds_fld2"}]
+ ];
+
+ pgm.addParam(p_inds, {name:"inds", by:"val", io:"both"});
+ pgm.addReturn("", "2A", {name:"output"});
+
+ let lookAtXML=pgm.toXML();
+ expect(lookAtXML).to.match(//);
+ expect(lookAtXML).to.match(//);
+ });
});