Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Note
titleContent Freeze
As of July 25th, 2023, there is a content freeze on this page.

This method is used for passing a parameter by reference either to JavaScript functions or with pjs.call().

Parameter

  1. "fieldName" - The name of the field as a string to pass. The field must already be defined using  pjs.define()
Note
Only one field can be passed to pjs.refParm() at a time.


Tip
When using pjs.call(), the use of pjs.refParm() is optional. When a declared field is passed as a parameter to pjs.call(), it is automatically converted to use pjs.refParm() internally. The explicit use of pjs.refParm() may be more efficient in some cases.


Return Value

An object that is used to pass the value by reference.

RPG Equivalent:  PARM


Examples

Code Block
languagejs
themeConfluence
titleCall an IBM i Program with By-Reference Parameter
collapsetrue
// Define fields using pjs.define(). 
pjs.define("myField1", {type: "packed decimal", length: 7, decimals: 2}); 
pjs.define("myField2", {type: "packed decimal", length: 8, decimals: 3}); 
pjs.define("myField3", {type: "packed decimal", length: 12, decimals: 5});


// Call using default parameter wrap, pjs.refParm(). 
pjs.call('mypgm1', myField1);


// Call using explicit parameter wrap, pjs.refParm(). 
pjs.call('mypgm1', pjs.refParm("myField1"));


Code Block
languagejs
titleCall an IBM i Program with By-Reference Parameters
collapsetrue
// Define fields using pjs.define(). 
pjs.define("myField1", {type: "packed decimal", length: 7, decimals: 2}); 
pjs.define("myField2", {type: "packed decimal", length: 8, decimals: 3}); 
pjs.define("myField3", {type: "packed decimal", length: 12, decimals: 5}); 
  
// Call using default parameter wrap, pjs.refParm(). 
pjs.call('mypgm2', myField1, myField2, myField3); 


// Call using explicit parameter wrap, pjs.refParm(). 
pjs.call('mypgm2', pjs.refParm("myField1"), pjs.refParm("myField2"), pjs.refParm("myField3"));


Code Block
languagejs
titleCall a JavaScript Function with a By-Reference Parameter
collapsetrue
// Define function double() that will receive a by reference parameter to multiply by two. 
function double(number) { 
  // Define temporary field number as type float. 
  pjs.define("number", { type: 'float', length: 8, refParm: number });   
  // Double value of number. 
  number = number * 2;   
  // Because the field is by-reference, there is no need for a return statement. 
} 
// Define myNum field as type float. 
pjs.define("myNum", { type: 'float', length: 8, initValue: 10 });   
// The initial value of 10 of myNum is changed to 20 after the function executes. 
double(pjs.refParm("myNum"));