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



Hi Doug,

A multiple occurrence data structure (MODS) is very similar to an array. It involves having 500 (in your example) copies of the same data structure all in memory, and being able to switch which copy is currently active by changing the "occurrence".

It's sort of like a file. There are many records in the file, and you access one at a time. So you can think of setting the occurrence of a data structure as being like chaining to a file. It changes which record is currently loaded in memory.

When you reference the data structure, you're referencing the current occurrence. When you pass that data structure as a parameter, you're passing that occurrence -- not all of them -- to the other program. It's just like a file! When you CHAIN to load a record into a DS, and then pass that DS, you only get the one record, not the whole file!

So what's the solution? I can think of two:

a) The best solution is to modernize -- the MODS is an old, outdated technique. Data structure arrays are the newer more modern way to do the same thing. If you switch to those, you can make the parameters work the way you expect. (You *do* have to include DIM() on the prototype and PI, though... LIKEDS won't do it.)

b) Since a MODS is stored in consecutive memory, you can use pointers to access the full MODS. Just pass the address of the FIRST instance, then set a basing pointer to that address. Have an identical MODS that's based on that basing pointer, and access the elements of that MODS. However, you'll have to be careful NOT to try to copy the MODS to a new field (as you did in your sample program) since that'll still result in only one occurrence.

The first alternative (a) is a better alternative because it makes it obvious what you're doing. Plus, you only have to define the DS once, which makes program maintenance simpler and easier. And, of course, you don't have to use pointers, which can be dangerous if you don't grok pointers.

The disadvantage to (a) is that you have to change the (possibly existing?) programs from MODS to DS arrays. Plus, (a) requires V5R2 or later (which isn't as much of a problem as it used to be, but still might affect you).

The second alternative (b) requires caution to make sure the MODS in both programs always match, and requires a better understanding of pointers/parameters, but won't require you to change the existing code.




Doug Palme wrote:
I am attempting to pass a Multiple occurence data structurre from one
program to another, but when it gets to the destination program, I only
have the first occurence, all others are lost.

Here is the code from the calling program:

0005.00 DEdtCstRtn PR ExtPgm('@EDTCSTRTN')
0006.00 D SubParm Like(MyStruct) 0007.00 D SubParm1 Like(Struct1)
0002.00 Dmystruct e ds ExtName(EDTCSTPF)
occurs(500)
0003.00 DStruct1 e ds ExtName(EDTCSTHDR)
I fill the structure and then call the second program

0031.00 Callp EdtCstRtn(MyStruct:Struct1);

Here is the code from the Called program:

0012.00 DCstRtnParm PR ExtPgm('@EDTCSTRTN')
0013.00 DPlistPR Like(PlistParm) 0014.00 DPlist1PR Like(Plist1) 0015.00 DCstRtnParm PI 0016.00 DPlistPI Like(PlistParm) 0017.00 DPlist1PI Like(Plist1)
0019.00 DPlistParm e ds ExtName(EDTCSTPF)
occurs(500)
0020.00 DPlist1 e ds ExtName(EDTCSTHDR)
First line in Main is PListParm = PListPI;

Howver, if I check the occurences for PListPI it only has one occurence
and that is before the eval statement.

Suggestions on what I may or may not be doing correctly
This transmission may contain information that is privileged, confidential
and/or exempt from disclosure under applicable law. If you are not the
intended recipient, you are hereby notified that any disclosure, copying,
distribution, or use of the information contained herein (including any
reliance thereon) is STRICTLY PROHIBITED. If you received this
transmission in error, please immediately contact the sender and destroy
the material in its entirety, whether in electronic or hard copy format.
Thank you.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
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.