AS400FileRecordDescription class for jtopen won't work on a client-side java application will it? It sounds like the compiled java file will need to reside on the as/400. Any help would be appreciated.
Announcement
Collapse
No announcement yet.
Noobie question
Collapse
X
-
Re: Noobie question
Yes, you can use the AS400FileRecordDescription from a remote client application. Establishing a connection via the AS400 class is all this is required.
The below code is not the best example but it should get you started:
PHP Code:public static void main(String[] args) throws AS400SecurityException,
IOException, AS400Exception, InterruptedException,
PropertyVetoException {
AS400 system = new AS400("MY_URL", "MY_USER", "MY_PASS");
system.connectService(AS400.RECORDACCESS);
AS400FileRecordDescription recordDescription = new AS400FileRecordDescription(
system, "/QSYS.LIB/MYLIB.LIB/MYFILE.FILE");
RecordFormat logFormat = null;
logFormat = recordDescription.retrieveRecordFormat()[0];
KeyedFile file = new KeyedFile(system, recordDescription.getPath());
file.setRecordFormat(logFormat);
file.open(AS400File.READ_WRITE, 0, AS400File.COMMIT_LOCK_LEVEL_NONE);
Record data = null;
Object[] key = new Object[3];
key[0] = new BigDecimal("001");
key[1] = "BBB";
key[2] = "123";
data = file.read(key);
int counter = 0;
while (data != null) {
++counter;
System.out.print(counter + "\t");
System.out
.print((data.getField("FIELD1").toString()).trim() + "\t");
System.out
.print((data.getField("FIELD2").toString()).trim() + "\t");
System.out
.print((data.getField("FIELD3").toString()).trim() + "\t");
System.out
.print((data.getField("FIELD4").toString()).trim() + "\t");
System.out
.print((data.getField("FIELD5").toString()).trim() + "\t");
System.out.println("");
data = file.readNextEqual(key);
if (counter >= 100) {
data = null;
}
}
file.close();
system.disconnectAllServices();
System.exit(0);
}
Last edited by kpmac; October 8, 2009, 08:51 AM.Predictions are usually difficult, especially about the future. ~Yogi Berra
Vertical Software Systems
VSS.biz
-
Re: Noobie question
I get an ExtendedIllegalArgumentException :key: length is not valid when I try and retrieve my records. Here's the DDS. I'm guessing it's my String object type doesn't jive with my AS/400 Character data type?
Code:* MODEL MASTER PHYSICAL FILE MOD00 UNIQUE R MODREC MODEL 15A TEXT('MODEL') DESC 35A TEXT('ITEM DESCRIPTION') PCFG 5S 0 TEXT('PALLET CONFIGURATION') K MODEL
Code:public static void main(String[] args) throws AS400SecurityException, IOException, AS400Exception, InterruptedException, PropertyVetoException { String system1 = "MY_SYSTEM"; String user = "MY_USER"; String pass = "MY_PASS"; String library = "dbillings1"; String object = "mod00"; AS400 system = new AS400(system1, user, pass); system.connectService(AS400.RECORDACCESS); AS400FileRecordDescription recordDescription = new AS400FileRecordDescription( system, "/QSYS.LIB/DBILLINGS1.LIB/MOD00.FILE"); RecordFormat logFormat = null; logFormat = recordDescription.retrieveRecordFormat()[0]; KeyedFile file = new KeyedFile(system, recordDescription.getPath()); file.setRecordFormat(logFormat); file.open(AS400File.READ_WRITE, 0, AS400File.COMMIT_LOCK_LEVEL_NONE); Record data = null; Object[] key = new Object[3]; key[0] = new String("001"); key[1] = "JR12A"; key[2] = "123"; data = file.read(key); int counter = 0; while (data != null) { ++counter; System.out.print(counter + "\t"); System.out .print((data.getField("MODEL").toString()).trim() + "\t"); System.out .print((data.getField("DESC").toString()).trim() + "\t"); System.out .print((data.getField("PCFG").toString()).trim() + "\t"); System.out.println(""); data = file.readNextEqual(key); if (counter >= 100) { data = null; } } file.close(); system.disconnectAllServices(); System.exit(0); }
Comment
-
Re: Noobie question
The java program is using three key values while your file contains a single key.
PHP Code://Change me ftom
Object[] key = new Object[3];
key[0] = new String("001");
key[1] = "JR12A";
key[2] = "123";
//to
Object[] key = new Object[1];
key[0] = "001";
Predictions are usually difficult, especially about the future. ~Yogi Berra
Vertical Software Systems
VSS.biz
Comment
Comment