|
If you decide to try the dynamic array approach, you need something like this - I've used a program described file for simplicity: If lookup speed is a major consideration take a look at the binary chop search technique an example of which was recently published in News/400 (the code is on the web). Alternatively prototype and use the C routine bsearch. FInpFile IF F 10 Disk * Note: the value supplied to the DIM statement is used by RPG as * the maximum size that the array can grow to - since the array * is being dynamically sized this is used as a "sanity check" * only. i.e. If it ever gets this big the program is looping !! D Array S Dim(20000) Based(Ptr) Like(InpData) D ArrayMax S 3 0 Inz(50) D Count S 5 0 Inz D Memory S 7 0 Inz IInpFile AA I 1 10 InpData * Allocate initial storage C Eval Memory = %Size(Array) * ArrayMax C Alloc Memory Ptr * Loop reading file and storing records in array C DoU %EOF(InpFile) C Read InpFile C If Not %EOF(InpFile) C Eval Count = Count + 1 C If Count > ArrayMax * Need more space - increase by 20 & reallocate C Eval ArrayMax = ArrayMax + 20 C Eval Memory = %Size(Array) * ArrayMax C REALLOC Memory Ptr C EndIf C Eval Array(Count) = InpData C EndIf C EndDo * Do whatever other processing is required * Don't forget to free up array when no longer needed C DEALLOC Ptr C Eval *InLR = *On +--- | This is the Midrange System Mailing List! | To submit a new message, send your mail to MIDRANGE-L@midrange.com. | To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com. | To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
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.