|
Hello,
In using VB and C I have the ability to dynamically increase an array's size from say 50 to 100 without losing the existing data, is this possible in RPG?
int test[10];
int x; for (x=1; x<=10; x++) {
test[x] = x;
} D test s 10I 0 dim(10)
D x s 10I 0 c for x = 2 to 11
c eval test(x) = x
c endfor int *test;
int maxelem;
int x; maxelem = 10;
test = malloc((maxelem+1) * sizeof(int)); for (x=1; x<=maxelem; x++) {
test[x] = x;
} maxelem = 20;
test = realloc(test, (maxelem+1) * sizeof(int)); for (; x<=maxelem; x++) {
test[x] = x;
}free(test);
D int s 10I 0
D p_test s *
D test s dim(32767)
D like(int)
D based(p_test)
D max s 10I 0
D x s 10I 0 c eval max = 10
c eval p_test = %alloc(%size(int) * max)
c for x = 1 to max
c eval test(x) = max
c endfor c eval max = 20
c eval p_test = %realloc( p_test
c : %size(int) * max)
c dow x < max
c eval x = x + 1
c eval test(x) = max
c enddoc dealloc p_test
Well, okay, the CPU probably doesn't actually say "hmm"
H DFTACTGRP(*NO)
D SetArrayPos PR
D Index 10I 0 value D max s 10I 0
D p_test s *
D p_elem s *
D elem s 10I 0 based(p_elem)
D max s 10I 0
D x s 10I 0 c eval max = 10
c eval p_test = %alloc(%size(elem) * max)
c for x = 1 to max
c callp SetArrayPos(x)
c eval elem = x
c endfor c eval max = 20
c eval p_test = %realloc( p_test
c : %size(elem) * max)
c dow x < max
c eval x = x + 1
c callp SetArrayPos(x)
c eval elem = max
c enddoc dealloc p_test
c eval *inlr = *on
P SetArrayPos B
D SetArrayPos PI
D Index 10I 0 value
c eval p_elem = p_test
c + (Index-1) * %size(Elem)
P EGood luck
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.