pjs.getInt()

pjs.getInt()

This API was added in Profound.js 5.8.0.

Description

pjs.getInt() interprets the contents of a strongly typed character field as a signed binary integer. This API is provided to facilitate conversion of IBM i CL programs to Profound.js.

Parameters

  1. 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.

  2. 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.

  3. Length (optional) - Can be 2 or 4. An error is thrown if the starting position plus the length exceeds the length of the field.

Examples

Example 1: Reading a 2-Byte Field

This example reads a 2-byte character field that a called program filled with a binary integer.

// Purpose: read a 2-byte binary integer returned by a called program. // A 2-byte character field used as a binary integer container. pjs.define("int16", { type: 'char', length: 2 }); // Program call assigns binary integer value to field. pjs.call("example", int16); // The whole field is 2 bytes, so no start position or length is needed. if (pjs.getInt(int16) === 1) { // Do something. }

Example 2: Reading Part of a Larger Field

This example reads 4 bytes from a specific position inside a 10-byte field, which is common when a CL program returns a structured parameter.

// Purpose: read a 4-byte binary integer from part of a larger field. pjs.define("p1", { type: 'char', length: 10 }); // Program call assigns binary integer into last 4 positions of field. pjs.call("example", p1); // Start at position 7 and read 4 bytes, which covers positions 7 through 10. if (pjs.getInt(p1, 7, 4) === 1) { // Do something. }

RPG Equivalent

None

CL Equivalent

%BINARY() / %BIN()


Related Pages