pjs.setInt()
This API was added in Profound.js 5.8.0.
Description
pjs.setInt() sets the contents of a strongly typed character field to a signed binary integer value. This API is provided to facilitate conversion of IBM i CL programs to Profound.js.
Parameters
Field name - The name of a character field defined with pjs.define(). The field length must be 2 or 4, unless the start position and length parameters are passed.
Value - A numeric value to set. Decimal values are converted to an integer by dropping the fractional amount.
Starting position (optional) - An integer >= 1 that specifies the starting position in the field. If the starting position is specified, then the length must be specified as 2 or 4.
Length (optional) - Can be 2 or 4. An error is thrown if the starting position plus the length exceeds the length of the field.
Example
Example 1: Writing and Reading a Binary Integer
This example writes a value into 4 bytes of a larger character field and then reads it back with pjs.getInt(), showing that the fractional amount is dropped.
// Purpose: write a binary integer into part of a character field and read it back.
// A 100-byte character field pre-filled with "x".
pjs.define("p", { type: "char", length: 100, initValue: "x".repeat(100) });
pjs.define("l", { type: "decimal", length: 5, decimals: 0 });
// Write 99.99 as a 4-byte binary integer at position 97.
// The fractional amount is dropped, so 99 is stored.
pjs.setInt(p, 99.99, 97, 4);
// Read the same 4 bytes back out.
l = pjs.getInt(p, 97, 4);
console.log(l); // Output: 99RPG Equivalent
None
CL Equivalent
%BINARY() / %BIN()