Using record blocking

The AS400File class uses record blocking to improve performance:

                       // 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.  Specify a blocking factor of 50.
     int blockingFactor = 50;
     myFile.open(AS400File.READ_ONLY, blockingFactor, AS400File.COMMIT_LOCK_LEVEL_NONE);

                       // Read the first record of the file.  Because
                       // a blocking factor was specified, 50 records
                       // are retrieved during this read() invocation.
     Record record = myFile.readFirst();
     for (int i = 1; i < 50 && record != null; i++)
     {

       // The records read in this loop will be served out of the block of
       // records cached on the client.
       record = myFile.readNext();
     }
                     ....

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

                       // Disconnect since I am done using
                       // record-level access
     sys.disconnectService(AS400.RECORDACCESS);
                       // 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 prior to invoking open()
     myFile.setRecordFormat(recordFormat);

                       // Open the file.  Specify a blocking factor of 50.
     int blockingFactor = 50;
     myFile.open(AS400File.WRITE_ONLY, blockingFactor, AS400File.COMMIT_LOCK_LEVEL_NONE);

                       // Create an array of records to write to the file
     Record[] records = new Record[100];
     for (int i = 0; i < 100; i++)
     {
                       // Assume the file has two fields,
                       // CUSTNAME and CUSTNUM
       records[i] = recordFormat.getNewRecord();
       records[i].setField("CUSTNAME", "Customer " + String.valueOf(i));
       records[i].setField("CUSTNUM", new Integer(i));
     }

                       // Write the records to the file.  Because the
                       // blocking factor is 50, only two trips to the
                       // server are made with each trip writing 50 records
     myFile.write(records);

                     ....

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

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