This file object method will open the file so the script is able to manipulate records within the chosen file. If you manually open a file, make sure you have a following close when you're finished with the file.
You only need to use open if you have defined your file with 'userOpen' as true.
Parameters
None.
Return Value
None.
Exception Handling
If there is a problem creating the data area, an Error will be thrown with the following properties:
- message - The IBM i message text.
- error - The message id.
- help - The message help text.
Examples
Example 1: Using .open() with userOpen
//Define the table. pjs.defineTable("productsp", { userOpen: true, read: true, keyed: true, levelIds: [ '4AFA8C636F188' ] }); //Create a DS based off of a record format from the table. pjs.define("myDS1", { type: 'data structure', likerec: { intrecname: 'products' }}); //Open and read the first record productsp.open(); productsp.fetchNext(false, null, pjs.ds("myDS1")); //Store a field in a variable var output = pjs.char(myDS1.prid);
Example 2: Using .open without userOpen - crash
pjs.defineTable("productsp", { read: true, levelIds: [ '4AFA8C636F188' ] }); pjs.define("data", { type: 'char', length: 50, varying: true }); pjs.setError(false); try { //Will crash because the file is already open productsp.open(); } catch(err) { pjs.setError(err); } if (pjs.error()) { // OPEN issued to a file already opened. data = 'Error ' + pjs.char(pjs.status()); } //By this point, data = "Error 1215"