pjs.tableLookupLT()
Description
This API allows you to find an element which is less than the argument you pass to it, and positions the table to that element.
An optional resulting indicators object can specify if any elements in the flags array should be set. The resulting indicators object can have this property:
low (Number) - Identifies the flag number to set if the nearest lower entry is found.
Parameters
Search argument - Value to search for.
Table array - The table to search.
Alternate table array (optional) - An alternating table to position along with the search table (OR the resulting indicators object).
Resulting indicators object (optional) - Flag numbers to set, as described above.
Return Value
Returns true if a matching element is found, or false if it is not. On a successful lookup the table is left positioned on the matching element, so referencing the table by name returns that element. On a failed lookup the table is restored to the position it held before the call.
Example
Suggest the Next Smaller Package Size
Purpose: When a customer asks for a package size that is out of stock, offer the
next size down. pjs.tableLookupLT() is used instead of
pjs.tableLookupLE()
because the requested size itself must be excluded from the result.
Prerequisites: boxSize is defined as a compile-time table
(table: true) in ascending sequence. This example uses the simplest two-parameter form,
with no alternating table and no resulting indicators.
Expected behavior: A request for the 16 oz size returns the 8 oz size. A request for the smallest size in the table (4 oz) returns false, because no smaller entry exists.
// Offer the next smaller package size when the requested size is unavailable.
pjs.define("boxSize", {
type: 'packed decimal', length: 5, decimals: 0, dim: 4,
table: true, orderBy: 'ASCEND',
initValue: [ 4, 8, 16, 32 ] // available package sizes, in ounces
});
pjs.define("wantedSize", { type: 'packed decimal', length: 5, decimals: 0, initValue: 16 });
pjs.define("suggestSize", { type: 'packed decimal', length: 5, decimals: 0 });
pjs.define("haveSmaller", { type: 'boolean' });
// Scan boxSize for the largest entry strictly less than 16. The 16 oz entry is
// skipped because it is equal, so the search stops on the 8 oz entry and leaves
// the table positioned there.
haveSmaller = pjs.tableLookupLT(wantedSize, boxSize);
if (haveSmaller) {
suggestSize = boxSize; // 8 - read from the element the table is positioned on
}
else {
// Returns false when wantedSize is already the smallest entry (for example 4).
// The table pointer is restored to its pre-call position in that case.
suggestSize = 0;
}RPG Equivalent
%TLOOKUPLT()