This is the way I would do it.
Build your structure like this:
D arrayDs DS based(pointer)
D Qualified
D static
D count 10I 0 Overlay(static)
D size 10I 0 Overlay(static : *NEXT)
D array 20A Dim(32767)
Use a template in a copybook if possable, because both the caller and called procedure need the definition.
Then, in the caller allocate the storage needed for the static part of the structure:
pointer = %Alloc(%Size(arrayDs.Static));
Call the procedure, making sure that the pointer is passed by reference.
In the called procedure, when you need more storage for your array do:
arrayDs.Size += %Size(arrayDs.Array * 200);
arrayDs.Count += 200;
piRtnListDynaArray = %ReAlloc(arrayDs.Size);
When you are done loading your array set the arrayDs.Count value to the last element in the array that was loaded, so that the caller knows how many elements of the array were loaded.
Duane Christen
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx]On Behalf Of Lim Hock-Chai
Sent: Friday, September 19, 2008 9:14 AM
To: RPG programming on the AS400 / iSeries
Subject: Dynamic Array as return/output parameter in export procedure
is there a way to safely return a dynamic array from an export procedure
to the caller? Something like below just doesn't look very safe for me.
P getListInDynaArray...
D pi
D piKey 4
D piRtnListDynaArray...
D *
D myDynaArray s 20 dim(32767) based(myDynaArray_p)
/free
myDynaAry_p = %alloc(200);
. . .
piRtnListDynaArray = myDynaArray_p
/end-free
--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at
http://archive.midrange.com/rpg400-l.
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit
http://www.messagelabs.com/email
______________________________________________________________________
NOTICE: This electronic mail transmission may contain confidential information and is intended only for the person(s) named. Any use, copying, or disclosure by any other person is strictly prohibited. If you have received this transmission in error, please notify the sender via e-mail.
As an Amazon Associate we earn from qualifying purchases.