|
>I was wondering if there was a code snippet somewhere that does a basic >record retrieval on a keyed file using an input field to get a specific >record. The key on the file is a packed 5 digit field. I know I have to >convert the input to BigDecimal . >I guess what I am looking for is an equivalent of an RPG Chain. Michael have a look at the attached code to give you an idea. It has 2 file ORDHDRK and ORDDTLK both of which are keyed by company number (2Alpha) and order number (6numeric). The program chains to the header with a fixed company order number (see "01",new java.math.BigDecimal(725075) }; bit) & then reads all detail recods with matching key summing the order quantity (ODQTYO) & order value (ODLVAL). One of the problems i encountered was that the readnextequal method worked similar to the RPG READE opcode but went beserk inasmuch as after reading all matching records, zoomed off thu' the rest of the file. For this reason, I have defined the CheckORDDTLKkey method which receives the keys & decides whether the next order number has been read. Not elegant but it works. The code works ok up until it tries to move the summed fileds into the label to present on the screen (never quite got this to work) The code was extracted out of Borland JBuilder2 (hence the Decorated frame bit) Mike import java.awt.*; import java.awt.event.*; import java.math.*; import com.ibm.as400.access.*; public class ORDframe extends DecoratedFrame { AS400 as400; KeyedFile ORDHDRKfile; KeyedFile ORDDTLKfile; AS400FileRecordDescription ORDHDRKfileDesc; AS400FileRecordDescription ORDDTLKfileDesc; RecordFormat ORDHDRKrecformat[]; RecordFormat ORDDTLKrecformat[]; Record ORDHDR; Record ORDDTL; Object[] key; Object[] nokey = new Object[] { }; TextField ODQTYO = new TextField(); TextField ODLVAL = new TextField(); Label label1 = new Label(); Label label2 = new Label(); public ORDframe() { try { // Create an AS400 connection object. as400 = new AS400("YOUR400","USER","PASSWORD"); // Create a file object. ORDHDRKfile = new KeyedFile(as400,"/qsys.lib/mspdta.lib/ORDHDRK.file"); ORDDTLKfile = new KeyedFile(as400,"/qsys.lib/mspdta.lib/ORDDTLK.file"); // Create a file ORDHDR description object. ORDHDRKfileDesc = new AS400FileRecordDescription(as400,"/qsys.lib/mspdta.lib/ORDHDRK.file"); ORDDTLKfileDesc = new AS400FileRecordDescription(as400,"/qsys.lib/mspdta.lib/ORDDTLK.file"); // Associate the ORDHDR format with the file object. ORDHDRKrecformat = ORDHDRKfileDesc.retrieveRecordFormat(); ORDDTLKrecformat = ORDDTLKfileDesc.retrieveRecordFormat(); // Associate the ORDHDR format with the file object. ORDHDRKfile.setRecordFormat(ORDHDRKrecformat[0]); ORDDTLKfile.setRecordFormat(ORDDTLKrecformat[0]); // Open the file. ORDHDRKfile.open(AS400File.READ_ONLY, 0, AS400File.COMMIT_LOCK_LEVEL_NONE); ORDDTLKfile.open(AS400File.READ_ONLY, 0, AS400File.COMMIT_LOCK_LEVEL_NONE); BigDecimal TotODQTYO = new BigDecimal(0); BigDecimal TotODLVAL = new BigDecimal(0); // Read a ORDHDR using the key array. key = new Object[] {"01",new java.math.BigDecimal(725075) }; if ( (ORDHDR = ORDHDRKfile.read(key)) != null ) { // Retrieve field values from the ORDDTL. ORDDTLKfile.positionCursorBefore(key); int eof = 0; while ( eof == 0 ) { if ((ORDDTL = ORDDTLKfile.readNextEqual(nokey)) != null) { if (( eof = CheckORDDTLKkey(key)) == 0) { TotODQTYO.add(new BigDecimal(ORDDTL.getField("ODQTYO").toString())); TotODLVAL.add(new BigDecimal(ORDDTL.getField("ODLVAL").toString())); } } else { eof = 1; } } } this.ODQTYO.setText(TotODQTYO.toString()); this.ODLVAL.setText(TotODLVAL.toString()); } catch (Exception e) {(TotODLVAL.toString());L.getField("ODLVAL").toString()));/ORDDTLK.file");yed System.err.println("Exception error: " + e); e.printStackTrace(); } } public int CheckORDDTLKkey(Object[] Keylist) { for (int i = 0 ; i<Keylist.length ; i++) { String keystring = new String(Keylist[i].toString()); try { String filekeystring = new String(ORDDTL.getField(ORDDTLKrecformat[0].getKeyFieldDescription(i).getFieldName().toString()).toString()); if (! keystring.equals(filekeystring)) { return (1); } } catch (Exception e) { System.err.println("Exception error: " + e); e.printStackTrace(); return(1); } } return(0); } public void CloseORDHDRK() { try { // Close the file. ORDHDRKfile.close(); } catch (Exception e2) { System.err.println("Close file Error: " + e2); e2.printStackTrace(); } } public void CloseORDDTLK() { try { // Close the file. ORDDTLKfile.close(); } catch (Exception e2) { System.err.println("Close file Error: " + e2); e2.printStackTrace(); } } void this_windowClosing(WindowEvent e) { // Close the file. CloseORDHDRK(); CloseORDDTLK(); System.exit(0); } } +--- | This is the JAVA/400 Mailing List! | To submit a new message, send your mail to JAVA400-L@midrange.com. | To subscribe to this list send email to JAVA400-L-SUB@midrange.com. | To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com. | Questions should be directed to the list owner: joe@zappie.net +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.