Array processing In RPG IV LIE

0 pts.
Tags:
Development
RPG
Is the aways to dynamicly increase an array before it would overflow. defined as 100 and while processing you need to increas it to say 110 or more. I think that there is aways to do this but I can't remember.
ASKED: February 11, 2005  7:30 PM
UPDATED: October 11, 2010  6:28 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

I saw this answer to your questions a while back:

Q. Does RPG have anything comparable to LotusScript’s or Visual Basic’s REDIM command that lets you redimension an array?

A. RPG IV doesn’t directly support arrays with a variable number of elements. You have to handle all the storage allocation yourself, and since you have no way to tell RPG what the new dimension of your array is, you’ll have to handle lookup and sort yourself, too. The advantage
of using a dynamically allocated array is that you don’t have to allocate storage that you aren’t going to use. The disadvantage is that your code becomes more complex.

There’s an example of managing dynamic arrays in the ILE RPG for AS/400 Programmer’s Guide at http://publib.boulder.ibm.com:80/cgi-bin/bookmgr/BOOKS/QB3AGY03/2.5.7.3 The sample code is more complex than what you require, as it also illustrates creating and using your own heap; however, you can skip the create-heap stuff and just use the ALLOC opcode if you want to use the default heap.

Another resource is the April 1997 issue of NEWS/400, which featured an article by Julian Monypenny titled “Dynamic Arrays with RPG IV.” The article discusses RPG IV’s dynamic memory management, nested
copies, and conditional compilation and provides source code for sorting and searching dynamic arrays. AS400 Network professional members can view the article and source code at http://www.as400network.com/article.cfm?ID=1772 .

Adapted from a newsgroup answer by IBM Toronto’s Barbara Morris

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • mygoodname
    Look at using ALLOC and REALLOC. Define your array as based on a pointer, then use ALLOC to assign the storage size of your array. If you need to enlarge it later, use REALLOC.
    0 pointsBadges:
    report
  • TSCHMITZ
    Hi, here is an example of ALLOC and REALLOC ...... d Ar_ordo s dim(100) based(p_Ar_ordo) d like(Elem_ordo) d Ar_Ordo_Max s 10i 0 Inz(10) Max Elem Ar_Ordo d Ar_Ordo_Idx s 10i 0 Inz(0) Cur Elem Ar_Ordo ..... * * Allocate Memory to Ar_Ordo * c Eval Memory = %size(Ar_Ordo) * Ar_Ordo_Max c Alloc Memory P_Ar_Ordo ..... * ** increase the storage if required * c if Ar_ordo_idx > Ar_ordo_Max c Eval Ar_Ordo_Max = Ar_Ordo_Idx c Eval Memory = %size(Ar_Ordo) * Ar_Ordo_Max c Realloc Memory P_Ar_Ordo c endif Hope it may help.
    470 pointsBadges:
    report
  • TomLiotta
    You can change memory allocations that an array is based on. But that doesn't redimension the array to change how many elements exist. If you must actually have an "array", you must dimension it for the maximum possible number of elements. Just make sure that you never reference an element that would be outside of the memory that you have allocated at any given moment. RPG isn't a language intended for this type of operation. It'd be better to use an appropriate language such as C. It might just be a bound C module that you call from the main RPG procedure. Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following