× 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.



... store your DS as varying to the pointer of the allocated storage would make the technique less complicate.

D*B



--------------------------------------------------
From: "Bryce Martin" <BMartin@xxxxxxxxxxxx>
Sent: Monday, November 22, 2010 3:46 PM
To: "RPG programming on the IBM i / System i" <rpg400-l@xxxxxxxxxxxx>
Subject: Re: Trying to get the size of a Datastructure through thepointer?Possible?Not having good luck with it...

Thanks for this Larry. It really gives me a bunch of thinking to do.
Great example, hopefully I can translate this into what I was thinking
about.


Thanks
Bryce Martin
Programmer/Analyst I
570-546-4777



Larry Ducie <larry_ducie@xxxxxxxxxxx>
Sent by: rpg400-l-bounces@xxxxxxxxxxxx
11/22/2010 06:02 AM
Please respond to
RPG programming on the IBM i / System i <rpg400-l@xxxxxxxxxxxx>


To
RPG400 <rpg400-l@xxxxxxxxxxxx>
cc

Subject
Re: Trying to get the size of a Datastructure through the pointer?
Possible? Not having good luck with it...







Hi Bryce,


As you are now aware this is not possible with the base RPG language.
But...

You can easily build your own mechanism for this.

Imagine a service program that contains three arrays:

1) an array of integers - reference
2) an array of integers - structure types
3) an array of pointers - structure addresses.

At each index would be a set of three values that uniquely identify a
structure by reference, type, and address.

You would register your structure as follows:

orderLine = Structure_newStructure( ORDER_LINE : %addr(MasterList_T) );

orderLine would be a unique reference to your structure and would be
associated with your structure type (ORDER_LINE) and address.

You can then pass the reference around on your calls and if you need to
know what is passed you would call:

type = Structure_getType( orderLine ); // or your local parameter
reference in place of orderLine

This would put the value of ORDER_LINE into type.

You could then base your local DS on the structure address:

D LocalDS...
D DS qualified based(address)
D Line...
D 3s 0
D Item...
D 15a
D Quantity...
D 11s 3
D LeadTimeDate...
D 8s 0

D address...
D 8s 0

D type...
D 8s 0



So...

type = Structure_getType( orderLine);

if type = ORDER_LINE;
address = Structure_getAddress( orderLine );
endif;


Now your localDS has the address of the structure associated with the
passed reference orderLine and you KNOW it is the correct structure type
because you checked the type.

The beauty of this is that your procedure is passed an integer and your
interface is future proofed if you create other structures. Your code is
also type=-safe as you only populate address once you KNOW the passed
structure is of type ORDER_LINE.

We use something similar (but much more sophisticated) and emulate
something akin to object references in RPG. With each index representing
the object reference, type, and instance variables. We have
getters/setters for each data item too:

For us we never expose the address and we would access the data in the
structure as follows:


quantity = OrderLine_getQuantity( orderLine );
OrderLine_setLeadTimeDate( orderLine : %dec(%date():8:0));

We can do this because we have separate service programs that do this for
all our business objects. We would create an OrderLine service program to
hold your structure.

So it is possible to have type-aware structures in RPG but it takes a
little work to set it up initially. It is well worth the effort,
especially as everything is an integer reference and generic routines are
truly generic!

Good luck, and have fun!

Cheers

Larry Ducie



--
This is the RPG programming on the IBM i / System i (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 message (including any attachments) is intended only for the use of the individual or entity to which it is addressed and may contain information that is non-public, proprietary, privileged, confidential, and exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any use, dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us and destroy this message immediately. --- --
This is the RPG programming on the IBM i / System i (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.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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.