SequentialFile

The SequentialFile class gives a Java™ program access to a file on the server by record number. Methods exist to position the cursor, read, update, and delete records by record number.

To position the cursor, use the following methods:
  • positionCursor(int) - set cursor to the record with the specified record number.
  • positionCursorAfter(int) - set cursor to the record after the specified record number.
  • positionCursorBefore(int) - set cursor to the record before the specified record number.
To delete a record, use the following method:
  • deleteRecord(int) - delete the record with the specified record number.
To read a record, use the following methods:
  • read(int) - read the record with the specified record number.
  • readAfter(int) - read the record after the specified record number.
  • readBefore(int) - read the record before the specified record number.
To update a record, use the following method:
  • update(int) - update the record with the specified record number.

SequentialFile is a subclass of AS400File; all methods in AS400File are available to SequentialFile.

The following example shows how to use the SequentialFile class:
     // Create an AS400 object, the file exists on this
     // server.
     AS400 sys = new AS400("mySystem.myCompany.com");

     // Create a file object that represents the file
     SequentialFile myFile = new SequentialFile(sys, "/QSYS.LIB/MYLIB.LIB/MYFILE.FILE/%FILE%.MBR");

     // Assume that the AS400FileRecordDescription class
     // was used to generate the code for a subclass of
     // RecordFormat that represents the record format
     // of file MYFILE in library MYLIB.  The code was
     // compiled and is available for use by the Java program.
     RecordFormat recordFormat = new MYFILEFormat();

     // Set the record format for myFile.  This must
     // be done before invoking open()
     myFile.setRecordFormat(recordFormat);

     // Open the file.
     myFile.open(AS400File.READ_WRITE, 0, AS400File.COMMIT_LOCK_LEVEL_NONE);

     // Delete record number 2.
     myFile.delete(2);

     // Read record number 5 and update it
     Record updateRec = myFile.read(5);
     updateRec.setField("CUSTNAME", newName);

     // Use the base class' update() method since I am
     // already positioned on the record.
     myFile.update(updateRec);

     // Update record number 7
     updateRec.setField("CUSTNAME", nextNewName);
     updateRec.setField("CUSTNUM", new Integer(7));
     myFile.update(7, updateRec);

     //  ....

     // Close the file since I am done using it
     myFile.close();

     // Disconnect since I am done using record-level access
     sys.disconnectService(AS400.RECORDACCESS);