|
First, don't loop through the whole file. If the users are modifying the records, then READC will be the fastest way to get the modified record. And don't forget that if there is an error, use the return record on next read flag. Saves a lot of headaches. Marvin -----Original Message----- From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of goodwink@xxxxxxxxxxxxxx Sent: Tuesday, August 09, 2005 12:59 PM To: RPG programming on the AS400 / iSeries Subject: Re: Subfile Processing When the user edits one of the displayed subfile records and hits enter I attempt to save it back to the correct file using a DOW to loop through each record returned from the subfile using READC(E) until I get an %EOF. In this loop I use a KLIST to search using SETLL(E) on the physical file to find the corresponding entry to the subfile entry I'm working on. If I get an %EQUAL result then I know it's an update to an existing record in the physical file so I use UPDATE(E) to write it out. Otherwise I use WRITE(E) to write the new record. This all works fine for the case of adding a new record, but when I go to update an existing one the changes don't make it back to the physical file. Any ideas? Thanks, Kyle Goodwin Extensicom LLC > Thank you, that was very helpful. I'd read all these things > individually one place or another, but putting them all together in one > spot it finally clicked. > > Kyle Goodwin > Extensicom LLC > > Jonathan Mason wrote: > >>Hi Kyle >> >>This is more a question about general programming than subfile design >>and programming, but here goes. >> >>A subfile is simply a means of storing and presenting related rows of >>information on a display. They are similar to database files in that >>they store multiple records, but they differ in that the records are >>stored in the jobs workspace rather than on disk. They also differ in >>that they are not keyed, but can be accessed using relative record >>numbers (RRN) or sequentially. >> >>Correct database design has the tables normalised, in other words broken >>down into their common form. For example, splitting an invoice into an >>invoice header file (INVOICES) and invoice lines file (LINEITEMS). This >>you have done with your tables. >> >>The INVOICES file would normally have a key relating to the invoice >>number (INVOICEID) and the LINEITEMS would have a composite key >>consisting of the INVOICEID and the invoice line number (INVOICELINE). >> >>When you load the records to your subfile you should use the INVOICEID >>to position the file cursor to the first invoice line for the invoice >>using the INVOICEID on a SETLL command and then loop through the file >>using the INVOICEID as the key: >> >>* Position to the start of the file... >>C Eval RRN = *Zeros >>C InvoiceID Setll(e) LineItems >> >> * Read through the file until all invoice lines loaded... >>C Dow Not %Eof >>C InvoiceID ReadE(e) LineItems >> >> * Populate the subfile record... >>C Eval SflFld1 = FileFld1 >>C Eval SflFld2 = FileFld2 >>C Eval SflFld3 = FileFld3 >> >> * Write the details to the subfile... >>C Eval RRN = RRN + 1 >>C Write Sfl >>C EndDo >> >>There are a number of techniques for loading subfiles, the above loads >>all records at once which you wouldn't normally use where large amounts >>of data are expected - it's only shown here as an example. >> >>The RRN is the position of the record in the subfile, so the first >>record written is RRN 1, the second RRN 2, etc. If you know how many >>records are in the subfile you can read the whole subfile using a loop: >> >>C For I = 1 to RRN >>C RRN Chain(e) LineItems >>C If %Found >>C ... >>C EndIf >>C EndFor >> >>A good guide to subfile programming is "The AS/400 Programmers Handbook" >>which has a large section on subfile programming. Alternatively you >>could check out the FAQ and the archives on this list. >> >>All the best >> >>Jonathan >> >> >> >> >> >> > > -- > This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list > To post a message email: RPG400-L@xxxxxxxxxxxx > To subscribe, unsubscribe, or change list options, > visit: http://lists.midrange.com/mailman/listinfo/rpg400-l > or email: RPG400-L-request@xxxxxxxxxxxx > Before posting, please take a moment to review the archives > at http://archive.midrange.com/rpg400-l. > >
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.