file.endOfData()

file.endOfData()

Description

file.endOfData() returns the end-of-file state of a specific database file, in the same way as the RPG %EOF(file) built-in function. It is called on the file instance created by pjs.defineTable(), using the internal file name (for example, productsp.endOfData()).

The state is set to true when a read operation (file.fetchNext(), file.fetchNextEqual(), file.fetchPrevious(), or file.fetchPreviousEqual()) finds no further record, and is reset to false when a record is read or the file is positioned successfully. It is also true after the file is closed.

Syntax

file.endOfData()

Parameters

None.

Return Value

A Boolean value: true if the end (or beginning) of the file was reached by the most recent read operation, otherwise false.

Exception Handling

This method does not throw an error.

Examples

Example 1: Control a Read Loop

The standard pattern for reading a file: read before the loop, test the end-of-file state, and read again at the end of each iteration.

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

Example 2: Check the State of One File When Several Are Open

Unlike pjs.endOfData(), which reflects the most recent read on any file, file.endOfData() is specific to one file. This matters when two files are read in the same loop.

pjs.defineTable("ordheader", { keyed: true, read: true }); pjs.defineTable("orddetail", { keyed: true, read: true }); ordheader.fetchNext(); while (!ordheader.endOfData()) { // Read the detail lines for this order. orddetail.positionTo(ohordno); orddetail.fetchNextEqual(ohordno); while (!orddetail.endOfData()) { orddetail.fetchNextEqual(ohordno); } // ordheader.endOfData() is still false here even though orddetail reached end of data. ordheader.fetchNext(); }

RPG Equivalent

%EOF(file_name)

Requirements

This API requires the Profound.js Connector module.


Related Pages