|
James Rich wrote:
>basically I want a 2-dimensional array that I
>can dynamically increase or decrease.
Jon Paris submitted this a while ago (see the Redbook for more fun with
pointers) It should server as a starting point. Any errors are due to my
changes:
PDYNARRAY b
DDYNARRAY pi
* 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(NAME)
D CurrElems S 3 0 Inz(50)
D RecordsRead S 5 0 Inz
D Memory S 7 0 Inz
* Allocate initial storage
C Eval Memory = %Size(Array) * CurrElems
C Alloc Memory Ptr
* Loop reading file and storing records in array
C DoU %EOF(Master)
C Read Master
C If Not %EOF(Master)
C Eval RecordsRead = RecordsRead + 1
* Limit this example to 200 records
C If RecordsRead > 200
C Leave
C EndIf
* Need more space - increase by 20 & reallocate
C If RecordsRead > CurrElems
C Eval CurrElems = CurrElems + 20
C Eval Memory = %Size(Array) * CurrElems
C REALLOC Memory Ptr 20
C EndIf
C Eval Array(RecordsRead) = NAME
C EndIf
C EndDo
* Don't forget to free up array when no longer needed
C DEALLOC Ptr
PDYNARRAY e
Buck Calabro
Aptis; Albany, NY
Billing Concepts Corp., a NASDAQ Listed Company, Symbol: BILL
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-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-2025 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.