Use the following as an example for your program.
import java.io.*; import java.util.*; import com.ibm.as400.access.*; public class RLACreateExample { public static void main(String[] args) { AS400 system = new AS400(args[0]); String filePathName = "/QSYS.LIB/MYLIB.LIB/MYFILE.FILE/MBR1.MBR";1try { SequentialFile theFile = new SequentialFile(system, filePathName); CharacterFieldDescription lastNameField = new CharacterFieldDescription(new AS400Text(20), "LNAME"); CharacterFieldDescription firstNameField = new CharacterFieldDescription(new AS400Text(20), "FNAME"); BinaryFieldDescription yearsOld = new BinaryFieldDescription(new AS400Bin4(), "AGE"); RecordFormat fileFormat = new RecordFormat("RF"); fileFormat.addFieldDescription(lastNameField); fileFormat.addFieldDescription(firstNameField); fileFormat.addFieldDescription(yearsOld); theFile.create(fileFormat, "A file of names and ages");2
theFile.open(AS400File.READ_WRITE, 1, AS400File.COMMIT_LOCK_LEVEL_NONE); Record newData = fileFormat.getNewRecord(); newData.setField("LNAME", "Doe"); newData.setField("FNAME", "John"); newData.setField("AGE", new Integer(63)); theFile.write(newData);3
theFile.close(); } catch(Exception e) { System.out.println("An error has occurred: "); e.printStackTrace(); } system.disconnectService(AS400.RECORDACCESS); System.exit(0); } }
![]() Previous |
---|