pjs.kds()
Description
pjs.kds() returns the sub-field values of a data structure as an array, in the same way as the RPG %KDS built-in function. The array is suitable for use as the search argument of file.positionTo(), file.positionAfter(), file.getRecord(), file.fetchNextEqual(), file.fetchPreviousEqual(), and file.delete().
This is useful when the key values are already held in a data structure, for example a key data structure defined with likerec or a data structure that matches the key fields of the file.
Syntax
pjs.kds(dataStructure)Parameters
Data structure (Data structure reference or String) - A reference to a data structure defined with pjs.define(), or a String containing the name of a data structure.
Return Value
An Array of the data structure's sub-field values, in the order the sub-fields are defined.
Exception Handling
A Profound.js Error is thrown in the following case:
name - Always
"Profound.js Error".message - A description of the problem.
statusCode - A numeric file status code, or
0when the error has no specific code. The same code is returned by file.status().
Conditions that cause this method to throw include:
First argument must be a data structure - The parameter is not a data structure defined with pjs.define().
Examples
Example 1: Position a File Using a Key Data Structure
A qualified data structure holds the two key values. pjs.kds() turns it into the array [100, 200], which is used to position the file.
pjs.define("keyDS", { type: "data structure", qualified: true, elements: {
"key1": { type: "packed decimal", length: 3, decimals: 0 },
"key2": { type: "packed decimal", length: 3, decimals: 0 }
}});
pjs.defineTable("mytable", { keyed: true, read: true });
keyDS.key1 = 100;
keyDS.key2 = 200;
// Equivalent to mytable.positionTo([100, 200]).
mytable.positionTo(pjs.kds(keyDS));Example 2: Read a Group of Records With a Key Data Structure
The same key data structure is reused for positioning and for reading all matching records.
pjs.define("keyDS", { type: "data structure", qualified: true, elements: {
"ordno": { type: "packed decimal", length: 7, decimals: 0 },
"line": { type: "packed decimal", length: 3, decimals: 0 }
}});
pjs.defineTable("orddetail", { keyed: true, read: true });
keyDS.ordno = 1001;
keyDS.line = 1;
orddetail.getRecord(pjs.kds(keyDS)); // read order 1001, line 1
if (orddetail.found()) {
// Process the line.
}RPG Equivalent
%KDS()
Requirements
This API requires the Profound.js Connector module.