Reputation: 2009
Is there a way to get number of elements in the array?
I have an array, dim 99 and char 8 length of each element. Elements get added though the program.
Something similar to size
in java or ruby
Array defenition:
DCL-S docs char(8) DIM(99) descend;
Set everything to blanks and add some strings to array
docs = *blanks;
docs(1) = 'doc1 ';
docs(2) = 'doc2 ';
What I have tried:
// Gives 8, size of each element, not size looking for
%size(docs);
// Gives 99, size of elements
%elem(docs);
The only thing that seems to work:
SORTA(D) docs;
count = %LOOKUP(*BLANKS : docs) - 1;
// count is 2 because thats how many documents were added
Another thing to consider, is what you do a dump, the variables are clearly organized into set ones and blank ones.
DOCS CHAR(8) DIM(99)
(1) 'DOC1 '
(2) 'DOC2 '
(3-99) ' '
Upvotes: 0
Views: 3774
Reputation: 1605
In short, no. RPG is not an object oriented language like Java or Ruby and as such arrays do not have built in procedures and data types. It is much closer to older non object-oriented procedural languages like C in that regard. As is the case with most language decisions, this causes some things to be easier and other things to be harder. In this case, you must keep track of array sizes and other details yourself if you need them.
Upvotes: 4