display.close()

display.close()

Description

display.close() closes a Rich Display File that is currently open, whether it was opened explicitly with display.open() or implicitly by pjs.defineDisplay(). Any record formats from the file that are still in the session's display layers are removed, the display's found and end of data states are reset, and the open indicator in the infDS data structure (if one was defined) is turned off.

After the file is closed, screen I/O methods such as display.screen.execute() throw error 1211 (I/O operation to a closed file) until the file is reopened with display.open(). Calling display.close() on a file that is not open does nothing.

Syntax

display.close()

Parameters

None.

Return Value

Nothing is returned.

Examples

Example 1: Close a Display File After Use

Opens a user-controlled display file, shows a screen, and closes the file when the module is finished with it.

Prerequisite: a Rich Display File named customer.json with a record format named detail that contains the fields custno, custname, and balance, and a button whose response property is bound to an indicator field named exit.

pjs.defineDisplay("display", "customer.json", { userOpen: true }); display.open(); custname = "ACME Corporation"; display.detail.execute(); // Logic to work with the display file fields goes here display.close(); // Release the display file

Example 2: Close and Reopen a Display File

A file can be reopened after it is closed. display.isOpen() shows the state at each step, and a screen I/O call made while the file is closed throws error 1211.

Prerequisite: a Rich Display File named customer.json with a record format named detail that contains the fields custno, custname, and balance, and a button whose response property is bound to an indicator field named exit.

pjs.defineDisplay("display", "customer.json"); // Opened implicitly display.close(); console.log(display.isOpen()); // false try { display.detail.execute(); // Not allowed while the file is closed... } catch (error) { console.log(error.message); // ...error 1211: I/O operation to a closed file } display.open(); // Reopen the file console.log(display.isOpen()); // true display.detail.execute(); // Screen I/O works again

RPG Equivalent

CLOSE


Related Pages