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



Booth,

One use for data structures is the one you describe where you are trying to
associated a bunch of fields together and pass them around as a group.
But a further consequence of data structures is that they influence
physically where the fields are stored in memory at runtime.

So, in the case of fields on a global file, if your file contains:
field1
field2
field3

Usually the fields would be stored in memory in that order (the order you
see them on the actual file). I say "usually" because I have seen examples
where this is not the case but have never researched the reasons.

If you decide that you are only interested in field1 and field3 and create
a DS with just those fields on - the compiler will ensure that field1 and
field3 are stored consecutively in memory. This allows it to define another
field name (your DS) with a pointer to field1 and a length of the combined
field1 and field3.

If you further tried to create a DS with field1 followed by field2, the
program would not compile because there is only 1 copy of each field held
in memory and it follows that field1 cannot be directly followed by both
field2 AND field3.

You can certainly have the same DS name in multiple sub procedures. The
issue is with the subfields.

Off the top of my head I'm not sure if it is legal for a sub procedure to
define a DS with a subfield which comes from the global space. I would
guess not, but certainly you couldn't have one sub procedure define one
order and another sub procedure define another order.

And remember that if you define a field in a sub procedure with the same
name as a global field - you will only ever see the local version in the
sub procedure.

If there is no overlap between the fields - e.g none of your sub procedures
require the same field name, then you could create a bunch of corresponding
data structures globally and pass those into a locally defined matching DS
(which could indeed be the same name in each sub procedure)

If there IS overlap between the fields (e.g the same field is required in
more than one sub-procedure) you would probably need to do something like
use qualified DS (so that the subfields are not directly referring to the
file fields) and use eval-corr opcode to move field names from file fields
to the DS fields.

There might be some clever tricks you can use with qualified ds and prefix
etc but ultimately your file fields can only be stored in one order in
memory.

I hope this makes sense.
Sorry I'm not working today or I'd illustrate with some code examples.

best regards,
Craig

On Sat, 29 Dec 2018 at 07:11, Booth Martin <booth@xxxxxxxxxxxx> wrote:

I have confused myself. Again.

Learning about service programs, prototypes, procedures and stumbling.

I I have a service program with which I wish to offer several procedures
relating to the various fields in a specific file.

Each procedure will have specific data structures dealing with the
fields related to that procedure. I would like to use the same data
structure name in several procedures although the fields will be
different in each data structure. It's not letting me do that. Then,
when I changed the names of the data structures it tells me that the
field names in the data structures are already defined.

So... how do I make data structures and field names that are local to
the procedure in which they reside? Or is that a you'll-be-sorry wish?

--
Booth Martin
www.martinvt.com
(870)576-9371
(802)461-5349

Just because your doctor has a name for your condition doesn't mean he
knows what it is.
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com


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.