Wednesday, March 11, 2015

DynamicRecordFormat

This DynamicRecordFormat is missing from another post about RJNE0100... Sorry about that...

So, again, I dig this up from my NAS and hopefully it helps. It is something from 10 years ago I kinda forgot why I ended up creating RecordFormat like this, but it worked for me at that time lol. Since I don't work in a place with the IBM machine anymore I just can't verify or test it. Should you find any problem please let me know.

package com.jvtech.as400;

import java.io.IOException;

import com.ibm.as400.access.*;

/**
 * 
 * @author Stanley Vong
 * 
 * 
 * @version 1.0 (March 28, 2005)
 * Initial Creation.
 * 
 */

public class DynamicRecordFormat extends RecordFormat{

 /**
  * Create an instance of RecordFormat using the AS400 and QSYSObjectPathName as reference.
  * @param as400
  * @param filePathName
  * @throws AS400Exception
  * @throws AS400SecurityException
  * @throws InterruptedException
  * @throws IOException
  */
 public DynamicRecordFormat(AS400 as400, QSYSObjectPathName filePathName) 
   throws AS400Exception, AS400SecurityException, InterruptedException, IOException {
  
  super (filePathName.getObjectName());
  AS400FileRecordDescription recordDescription =
   new AS400FileRecordDescription(as400, filePathName.getPath());
  RecordFormat[] fileFormat = recordDescription.retrieveRecordFormat();

  if (fileFormat.length > 1){
   throw new IllegalArgumentException(filePathName.getPath() + " contains more than one record format.");
  }  
  //always default to fileFormat[0] cause only physical files are assumed here.
  FieldDescription fd = null;
  for (int i = 0; i < fileFormat[0].getNumberOfFields(); i++){
   fd = fileFormat[0].getFieldDescription(i);
   addFieldDescription(fd);
  }
 }
}