Data Area API
Overview
The Data Area API contains the Profound.js APIs used to read, write, lock, unlock, and create IBM i data areas. These APIs are the Profound.js equivalents of the RPG IN, OUT, and UNLOCK operation codes, and of the CRTDTAARA CL command.
There are two ways to work with a data area in Profound.js. Both approaches can be used in the same module.
Declared Data Areas
A field is tied to a data area object when the field is defined, by adding the dataArea configuration property to pjs.define(). Profound.js then moves the data area contents in and out of that field and handles the data conversion for you. This is the closest equivalent to an RPG data area data structure.
Declaring and reading a data area field
// Tie a 50-byte character field to the CUSTDA data area in MYLIB.
// The field length controls how many bytes are read, starting at position 1.
pjs.define("custInfo", { type: 'char', length: 50, dataArea: 'MYLIB/CUSTDA' });
// Read the data area into the field.
pjs.retrieveDataArea(custInfo, false);
return custInfo;The following APIs operate on fields that were declared this way:
pjs.retrieveDataArea() - Reads one declared data area into its field.
pjs.setDataArea() - Writes one field back to its data area.
pjs.retrieveAllAreas() - Reads every declared data area in the module.
pjs.setAllAreas() - Writes every declared data area in the module.
pjs.unlockDataArea() - Releases the lock on one declared data area.
pjs.getDataAreaList() - Lists the fields in the module that declare a data area.
pjs.closeDataAreas() - Writes back and/or unlocks every declared data area.
Data Areas Accessed by Name
The data area is read and written directly by object name, with no pjs.define() declaration. Your code works with a raw Buffer in IBM i internal format, so you are responsible for any data conversion.
pjs.getDataArea() - Reads bytes from a data area by name.
pjs.putDataArea() - Writes bytes or a number to a data area by name.
Creating a Data Area
pjs.createDataArea() - Creates a data area object on IBM i and optionally initializes it.
Locking
When Profound.js locks a data area, it allocates the object with an *EXCLRD (exclusive, allow read) lock scoped to the job. The allocation does not wait, so the call fails immediately if the lock cannot be granted. Unlocking releases that same allocation.
A named data area must be locked before Profound.js will write to it. If you call pjs.setDataArea() for a field whose data area is not locked, Profound.js Error 412 (Data area not locked for output) is thrown. Lock the data area by passing true as the lock argument on pjs.retrieveDataArea(). The special data areas *LDA, *GDA, and *PDA belong to the job, are never locked, and are exempt from this rule.
Requirements
The APIs in this section require the Profound.js Connector module.