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:

To delete a record, use the following method:

To read a record, use the following methods:

To update a record, use the following method:

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);