pjs.defineProc()
Â
This API defines a JavaScript function that maps to an external procedure in an IBM i service program, similar to a prototype in an ILE program.
If a function by the same name is already exported by pjs.requireServiceProgram() or pjs.requireModule() API, the call to pjs.defineProc() will have no effect, and the exported functions will be utilized instead of the external procedure specified by pjs.defineProc().
Parameters
Function name - A String that specifies the name of the JavaScript function to create within the current scope
Configuration - an object with the following properties:
srvpgm (optional) -Â A String containing the name of the service program to use. The service program name can be quailed with a library, otherwise the library list will be used to resolve the service program. If the service program is not specified, the API will attempt to resolve the procedure automatically.
extProc (optional) - A string containing the name of the external procedure in the service program. If not specified, the procedure name is assumed to be the same as the Function name.
parms - An array of parameter definitions. Each parameter definition is a configuration object of the format used by pjs.define(). Optionally, you can attach a name property to the configuration objects to identify parameter names; however, the name is for informational purposes only and is not used internally by the API. Each configuration object may also contain a byRef true or false property, which specifies whether the parameter is passed by reference. The default value for byRef is false. Reference parameters can have an optional "const" true/false property. When const is true, a copy of the parameter value will be passed by reference to the procedure, and the original parameter value will not be modified. The default value for const is false. pjs.refParm() must be used when calling the function and passing parameters by reference unless const is true.
result (optional) - A configuration object of the format used by pjs.define(), which defines the procedure's return value. This property should only be specified if the procedure has a return value.
Examples
Calling a System API
// Define external procedure
pjs.defineProc("sqrt", {
srvpgm: "QSYS/QC2UTIL1",
parms: [
{ type: 'float', length: 8 }
],
result: { type: 'float', length: 8 }
});
// Use external procedure as a simple function
console.log(sqrt(16)); // output is 4 (the square root of 16)
Â
Calling a procedure in your own service program
// Define external procedure
pjs.defineProc("getItemPrice", {
srvpgm: "PGMLIB/SALESORDER",
extProc: "GETPRICE"
parms: [
{ type: "packed decimal", length: 7, decimals: 0 }
],
result: { type: "packed decimal", length: 9, decimals: 2 }
});
// Use external procedure as a simple function
price = getItemPrice(itemNumber);
Â
Passing parameters by reference
// Define external procedure
pjs.defineProc("addressAutoCorrect", {
srvpgm: "PGMLIB/SALESORDER",
extProc: "FIXADDR"
parms: [
{ name: "addressLine1", type: "char", length: 30, byRef: true },
{ name: "addressLine2", type: "char", length: 30, byRef: true },
{ name: "city", type: "char", length: 20, byRef: true },
{ name: "state", type: "char", length: 2, byRef: true },
{ name: "zip", type: "decimal", length: 5, decimals: 0, byRef: true }
]
});
// Use external procedure as a JavaScript function
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 });
addressLine1 = "562 CONGRESS PRK"
city = "CENTERVILLE";
state = "OH",
zip = 45458;
addressAutoCorrect(pjs.refParm("line1"), pjs.refParm("line2"), pjs.refParm("city"), pjs.refParm("state"), pjs.refParm("zip"));
Â
Requirements
This API requires the Profound.js Connector module.
Some documentation pages have recently moved to a new section: Profound AppDev. If you are having trouble finding specific pages, try the documentation search capability or reach out to our Support team!