pjs.callProc()
Description
This method is used to call an ILE procedure using Profound.js fields as arguments.
Parameters
Argument / result definition - An object with the following properties:
srvpgm - A String containing the name of the service program to call. The service program name can be qualified with a library; otherwise, the library list will be used to resolve the service program.
procedure - A String containing the name of the procedure to call. Keep in mind that ILE procedure names are case-sensitive. RPG procedure export names are typically in uppercase.
arguments (optional) - An array of argument definition objects with the following properties:
field - A String containing the Profound.js field name to pass.
byRef - Set to Boolean true to pass the field by reference. Otherwise, the field will be passed by value.
Argument definitions for pointer type can have additional options:
string (Boolean) - Set to true to truncate data sent to the backend at the position where a null byte is located in the buffer. If no null byte is found, the entire buffer will be passed.
dataLen (Number) - Set to a positive integer to limit the amount of data sent to the backend for the pointer parameter. If the buffer pointed to by the pointer is longer than this number, it will be truncated. This option is ignored if
stringis specified.
result (optional) - A String containing a field name that will receive the procedure’s return value.
Starting in version 7.21.0, parameters can be omitted by passing a nullish value for an arguments array entry. This is equivalent to passing *OMIT in RPG.
Exception Handling
An Error instance will be thrown with the following properties:
message - The IBM i message text.
error - The message id.
help - The message help text.
Examples
Call an RPG Subprocedure With a Parameter and a Return Value
// Calls procedure GETPRICE, exported from service program PGMLIB/SALESORDER.
// The procedure takes one packed(7,0) item number and returns packed(9,2).
// pjs.callProc() works with Profound.js field NAMES, so both the argument and
// the result must be defined with pjs.define() first.
function getPrice(item) {
// "parm:" binds the incoming JavaScript argument to a strongly typed field.
pjs.define("item", { type: "packed decimal", length: 7, decimals: 0, parm: item });
pjs.define("price", { type: "packed decimal", length: 9, decimals: 2 });
pjs.callProc({
srvpgm: "PGMLIB/SALESORDER", // library-qualified; omit the library to use the library list
procedure: "GETPRICE", // ILE names are case-sensitive -- RPG exports are usually uppercase
arguments: [
{ field: "item" } // passed by value, since byRef defaults to false
],
result: "price" // the procedure's return value is copied into "price"
});
return price;
}
const price = getPrice(1234);
console.log(price);Call a Subprocedure and Pass Parameters by Reference
// Calls procedure CORRECT in PGMLIB/ADDRESSES, which cleans up an address in
// place. Every parameter is passed by reference, so the procedure writes its
// corrected values straight back into the caller's fields.
function addressAutoCorrect(addrLine1, addrLine2, city, state, zip) {
// "refParm:" binds each incoming pjs.refParm() wrapper to a local field of
// the exact type and length the ILE procedure expects.
pjs.define("addressLine1", { type: "char", length: 30, refParm: addrLine1 });
pjs.define("addressLine2", { type: "char", length: 30, refParm: addrLine2 });
pjs.define("city", { type: "char", length: 20, refParm: city });
pjs.define("state", { type: "char", length: 2, refParm: state });
pjs.define("zip", { type: "decimal", length: 5, decimals: 0, refParm: zip });
pjs.callProc({
srvpgm: "PGMLIB/ADDRESSES",
procedure: "CORRECT",
arguments: [
{ field: "addressLine1", byRef: true },
{ field: "addressLine2", byRef: true },
{ field: "city", byRef: true },
{ field: "state", byRef: true },
{ field: "zip", byRef: true }
]
});
}
// Caller: define the fields that will receive the corrected address.
pjs.define("line1", { type: "char", length: 30 });
pjs.define("line2", { type: "char", length: 30 });
pjs.define("city", { type: "char", length: 20 });
pjs.define("state", { type: "char", length: 2 });
pjs.define("zip", { type: "decimal", length: 5, decimals: 0 });
line1 = "562 CONGRESS PRK";
city = "CENTERVILLE";
state = "OH";
zip = 45458;
// pjs.refParm() is required here so the procedure can update the caller's fields.
addressAutoCorrect(pjs.refParm("line1"), pjs.refParm("line2"),
pjs.refParm("city"), pjs.refParm("state"), pjs.refParm("zip"));
console.log(line1, line2, city, state, zip); // now holds the corrected addressRPG Equivalent
CALLP
Requirements
This API requires the Profound.js Connector module.