Dynamic array

1,420 pts.
Tags:
AS/400
AS/400 Arrays
I want to declare the number of elements of an array dynamically in RPGLE. How to do it? Please reply.

Software/Hardware used:
AS400,RPG,CLLE,Db2400.
ASKED: April 4, 2013  3:29 PM
UPDATED: April 4, 2013  4:03 PM

Answer Wiki

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

Discuss This Question: 5  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
  • CharlieBrowne
    If you do a google search you will find many articles and examples on how to do this. I would also suggest you download the IBM RPG reference manual for whatever OS release you are running.
    39,790 pointsBadges:
    report
  • TomLiotta
    Technically, you can't declare a dynamic number of elements for an array. Instead, you allocate a variable amount of memory according to how many elements you want. Then you can use a basing pointer to apply an element definition to the allocated memory. By offsetting the pointer, you can apply the definition to anywhere in the allocated memory to store or retrieve any "element". Alternatively, you can declare an actual array over allocated memory. Declare it with the maximum elements, and simply avoid accessing any elements beyond allocated memory. -- Tom
    125,585 pointsBadges:
    report
  • Sai4AS400
    Hi Tom, Thanks for your answer. But how to initialize the array elements in this case?
    1,420 pointsBadges:
    report
  • TomLiotta
    Start the basing pointer at the start of the memory allocation (which cannot exceed 16MB, so you can't do it for 70M elements), initialize the first element, increment the pointer by the size of the element, initialize the next element, and repeat as often as needed. -- Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    Also, if you want to initialize a large memory block with spaces, low- or high-values or any single byte value, the memset() C library function can be best. -- 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