A simple class that will construct and deconstruct buffers (which is actually just a single) to be passed into an ILE program. This is particularly useful when it comes to working with data structures.
Don't fancy writing all this code manually? Check out this nifty tool to do it for you!
const inputDS = new rpgleDS(...);
const responseDS = new rpgleDS(...);
static async getHistoryHeader(header) {
console.log(inputDS.getSize());
console.log(responseDS.getSize());
const inBuffer = inputDS.toBuffer(header);
const results = await db2.callProcedure(SCHEMA, 'PROGRAM', [inBuffer, undefined]);
return responseDS.fromBuffer(results.parameters[1]);
}
JS Type | ILE Type |
---|---|
String | Char |
Number | Zoned |
Boolean | Char(1) / Ind |
{
"name": "25",
"number": 25
}
const base = new rpgleDS(
[
{
"name": "name",
"length": 25
},
{
"name": "number",
"length": 11,
"decimals": 2
}
]
);
Dcl-Ds base Qualified Template;
name Char(25);
number Zoned(11:2);
End-Ds;
The class can easily handle many levels of structs (likeds(x) qualified
).
{
"name": "25",
"number": 25,
"substructA": {
"a": "10",
"b": 10
}
}
const substructA = new rpgleDS(
[
{
"name": "a",
"length": 10
},
{
"name": "b",
"length": 11,
"decimals": 2
}
]
);
const base = new rpgleDS(
[
{
"name": "name",
"length": 25
},
{
"name": "number",
"length": 11,
"decimals": 2
},
{
"name": "substructA",
"like": substructA
}
]
);
Dcl-Ds substructA Qualified Template;
a Char(10);
b Zoned(11:2);
End-Ds;
Dcl-Ds base Qualified Template;
name Char(25);
number Zoned(11:2);
substructA LikeDS(substructA);
End-Ds;
We also support substructs that are arrays.
{
"name": "25",
"number": 25,
"substructA": [{
"a": "10",
"b": 10
}]
}
const substructA = new rpgleDS(
[
{
"name": "a",
"length": 10
},
{
"name": "b",
"length": 11,
"decimals": 2
}
]
);
const base = new rpgleDS(
[
{
"name": "name",
"length": 25
},
{
"name": "number",
"length": 11,
"decimals": 2
},
{
"name": "substructA",
"like": substructA,
"dim": 5
}
]
);
Dcl-Ds substructA Qualified Template;
a Char(10);
b Zoned(11:2);
End-Ds;
Dcl-Ds base Qualified Template;
name Char(25);
number Zoned(11:2);
substructA LikeDS(substructA) Dim(5);
End-Ds;