SequentialFile

The SequentialFile class gives a Java program access to an AS/400 file 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:

  • 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
                       // AS/400.
     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 prior to 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);


[ Legal | AS/400 Glossary ]