Can I Declare a variable-length Array?

620 pts.
Tags:
AS/400
RPG ILE
RPG/400
Is it possible to Declare a variable-length Array viz.. like we have in "VARLEN" in DDS?

Software/Hardware used:
RPGILE, RPG/400, AS/400

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: 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
  • philpl1jb
    Sure in RPGLE but not in RPG/400 . The length of each field can be varing, but not the number of elements. D Temp60 S 60 Varying DIM(30) Each element of Temp60 will take 62 bytes of memory. If the data isn't coming from a varchar field you will have to %Trim whatever field it comes from. You may also have to deal with null value issues. Phil
    50,565 pointsBadges:
    report
  • TomLiotta
    Can I Declare a variable-length Array? Do you want the array to be varying? Or do you want the array elements to be varying? If you want an array to hold more or fewer elements at different times, you'll need to use ILE RPG. The array will be defined with DIM() that declares the maximum number of elements allowed. It will also be defined over memory that is allocated at run-time to cover the size that you need. Use the ALLOC, REALLOC and DEALLOC statements to manipulate the allocated memory. (There are also %alloc() and %realloc() builtin functions.) When you allocate memory for a number of elements, it is your responsibility not to reference an element beyond the end of your memory, regardless of how many elements were declared in the DIM() keyword. Alternatively, you don't actually need a DIM(). After you allocate some memory, you can simply use pointer increments and decrements to set a new position for a variable or for a DS. Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    So answer is yes, for RPGLE for two different ways of reading the question Answer is no for RPG/400.
    50,565 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