Page tree
Skip to end of metadata
Go to start of metadata

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().


  1. Function name - A String that specifies the name of the JavaScript function to create within the current scope
  2. 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. pjs.refParm() must be used when calling the function and passing parameters by reference.
    • 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.


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", {
  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", {
  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"
state = "OH",
zip = 45458; 
addressAutoCorrect(pjs.refParm("line1"), pjs.refParm("line2"), pjs.refParm("city"), pjs.refParm("state"), pjs.refParm("zip")); 


This API requires the Profound.js Connector module.