× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



In my case, the caller does not really know how many elem is needed.
The called procedure (export procedure) determines that. From your
example, are you saying that the %realloc would trick the system to
think that the heap storage belongs to the caller? Or am I over
thinking?

Note: The export procedure could get called multiple times before the
caller dealloc the dyna array. Making the array static in the export
procedure might not work for me.



From

"Christen, Duane J." <Duane.Christen@xxxxxxxxxxxxx> wrote in message
news:<mailman.11963.1221835629.2545.rpg400-l@xxxxxxxxxxxx>...
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.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 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.