pjs.endOfData()

pjs.endOfData()

Description

pjs.endOfData() returns the program-level end of data state, which is set by the most recent read operation on any file in the module, in the same way as the RPG %EOF built-in function when it is used without a file name. The API can also be called as pjs.endOfFile() or pjs.eof().

The state is updated by:

Because every read operation on every file overwrites the same value, use the file-specific form when more than one file is involved: file.endOfData() for a database file, or display.endOfData() for a display file. A typical case is a loop that reads a database file while processing changed grid records.

Syntax

pjs.endOfData()

Parameters

None.

Return Value

A Boolean value: true if the most recent read operation reached the end (or beginning) of the file, or, for a display file, if the last readChanged() found no more changed records; otherwise false.

Exception Handling

This method does not throw an error.

Examples

Example 1: Control a Read Loop on a Single File

Only one file is read, so the global end-of-data state is safe to use.

pjs.defineTable("productsp", { read: true }); productsp.fetchNext(); while (!pjs.endOfData()) { // Process the record. productsp.fetchNext(); }

Example 2: Process Changed Grid Records in a Rich Display File

The READC loop written with the program-level API. No other file is read inside the loop, so the state always reflects the last readChanged().

Prerequisite: a Rich Display File named subfiled.json with a control record format named ctl and a grid whose record format name is sfl, with the fields product, description, and quantity bound to its columns.

pjs.defineDisplay("display", "subfiled.json", { rrnFields: { sfl: "RRN" } }); pjs.define("RRN", { type: "integer" }); // ... load the grid records with display.sfl.write() here ... display.ctl.execute(); // Display the control format and the grid // Process all grid records changed by the user display.sfl.readChanged(); while (!pjs.endOfData()) { console.log("Record " + RRN + " changed: quantity is now " + quantity); display.sfl.readChanged(); }

RPG Equivalent

%EOF


Related Pages