pjs.call()
Description
This method calls a Profound.js module or an IBM i program.
Parameters
Profound.js module or IBM i program name (String) - The name can be qualified with a directory (Profound.js module) or a library (IBM i). If the name is not qualified, either the pathlist or the IBM i job library list will be used to resolve it. If a Profound.js module of the given name is not found on the local file system and the Profound.js Connector is configured, then the name is assumed to be an IBM i program name.
– or –
Function - A function exported from a module loaded with pjs.require().Parameters (optional) - One or more parameters. Parameters can be either primitive JavaScript values (String, Number, etc.) or parameter objects returned by pjs.parm() and pjs.refParm(). Field names can also be passed; these are automatically wrapped by
pjs.refParm()internally.pjs.parm()orpjs.refParm()must be used for all parameters to IBM i programs. Passnullto omit a parameter.
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 IBM i Program With Input and Output Parameters
Call IBM i Program w/Input and Output Parameters
// Prerequisites: IBM i program MYPGM is on the job's library list, and the
// Profound.js Connector is configured. MYPGM takes two parameters:
// 1) packed(7,2) input 2) packed(15,2) output
const input = 123;
// Define the output field so the program has a buffer to write into.
pjs.define("output", { type: "packed decimal", length: 15, decimals: 2 });
// pjs.refParm() with "const: true" converts the primitive 123 into a read-only
// packed(7,2) buffer, so MYPGM cannot change it.
// "output" is a declared field, so pjs.call() wraps it with pjs.refParm()
// automatically -- whatever MYPGM writes there comes back in "output".
pjs.call("mypgm",
pjs.refParm(input, { const: true, type: "packed decimal", length: 7, decimals: 2 }),
output);
console.log(output); // the value MYPGM returned in parameter 2Call a Profound.js Module
Call a Profound.js module by name
// "orders/recalc.js" lives under the modules directory (or anywhere on the
// pathlist). Profound.js resolves the name locally first; only when no module
// is found does it fall back to calling an IBM i program of the same name.
pjs.define("orderNo", { type: "packed decimal", length: 7, decimals: 0, initValue: 4711 });
pjs.define("newTotal", { type: "packed decimal", length: 11, decimals: 2 });
// Declared fields are wrapped with pjs.refParm() automatically, so recalc.js
// can update newTotal in place.
pjs.call("orders/recalc", orderNo, newTotal);
console.log(`Order ${orderNo} now totals ${newTotal}`);Call a Function Loaded With pjs.require()
Call an exported function
// Load the module once, then call an exported function through pjs.call().
// Passing the function itself -- rather than a name -- skips name resolution,
// which is useful when the module is loaded once at startup.
const pricing = pjs.require("orders/pricing.js");
pjs.define("itemNo", { type: "char", length: 15, initValue: "WIDGET-001" });
pjs.define("price", { type: "packed decimal", length: 9, decimals: 2 });
pjs.call(pricing.getPrice, itemNo, price);
console.log(price);Omit a Parameter
Pass null to omit a parameter
// MYPGM accepts three parameters, but the second one is optional -- the program
// checks for a null pointer before using it. Passing null omits that parameter
// on calls to IBM i: the program receives a null pointer, the same as *OMIT.
pjs.define("custNo", { type: "packed decimal", length: 7, decimals: 0, initValue: 100 });
pjs.define("results", { type: "char", length: 50 });
pjs.call("MYPGM", custNo, null, results);
console.log(results);RPG Equivalent
CALL
Requirements
This API requires the Profound.js Connector module.