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



At a glance, it looks like all assignment code, so for lines like this:
mystruct(x).field1 = value;

Would be (spacing not correct):
Eval mystruct(x).field1 = value


-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Doug Palme
Sent: Friday, January 02, 2009 9:07 AM
To: RPG programming on the IBM i / System i
Subject: Re: Multiple Occurence Data Structure losing occurences on pass

Thanks Scott,
One final question - how would the coding of this differ with fixed
format? The reason I ask is I would like to pass this along to a few
others in the building but not everyone here knows how to code free
format.

From: Scott Klement <rpg400-l@xxxxxxxxxxxxxxxx>

To: RPG programming on the IBM i / System i
<rpg400-l@xxxxxxxxxxxx>
Date: 12/31/2008 03:50 PM

Subject: Re: Multiple Occurence Data Structure losing occurences on
pass


----------------------------------------------------------------------

Scott Klement wrote:
> So what's the solution? I can think of two:
>
> a) The best solution is to modernize [SNIP]
>
> b) Since a MODS is stored in consecutive memory, you can use
pointers
[SNIP]

Here are (untested) examples of the two options I described in my
previous e-mail

====== OPTION A: USE DS ARRAYS ======

Copy book for EDTCSTRTN:

D EdtCstRtn_Subparm_t
D e ds extname(EDTCSTPF)
D qualified
D BASED(TEMPLATE)
D EdtCstRtn_Plist1_t
D e ds extname(EDTCSTHDR)
D qualified
D BASED(TEMPLATE)

DEdtCstRtn PR ExtPgm('@EDTCSTRTN')
D SubParm likeds(EdtCstRtn_Subparm_t)
D dim(500)
D SubParm1 Likeds(EdtCstRtn_Plist1_t)

In the caller program... make sure to /COPY copybook, and
then code:

Dmystruct ds likeds(EdtCstRtn_Subparm_t)
D dim(500)
DStruct1 e ds ExtName(EDTCSTHDR)

instead of OCCUR or %OCCUR, reference mystruct as
an array. For example:

mystruct(x).field1 = value;
mystruct(x).field2 = value2;
... etc ...

Callp EdtCstRtn(MyStruct:Struct1);

In the called program, do this:

DEdtCstRtn PI
D PlistPI likeds(EdtCstRtn_Subparm_t)
D dim(500)
D PlistPI1 Likeds(EdtCstRtn_Plist1_t)

and reference the data as:

PListPI(x).field1
PLISTPI(x).field2
etc

and reference the 2nd parm as:

PlistPI1.field1
PlistPI1.field2
etc

Note that the layout of the DS is defined in only one place -- the
copy
book. Since you /COPY the same thing in both places, you get the
precise
same definition each time... and that's a very good thing, it
protects
you against errors.

====== OPTION B: USE MODS w/POINTERS ======

DEdtCstRtn PR ExtPgm('@EDTCSTRTN')
D SubParm Like(MyStruct)
D SubParm1 Like(Struct1)

Dmystruct e ds ExtName(EDTCSTPF)
D occurs(500)
DStruct1 e ds ExtName(EDTCSTHDR)

I fill the structure and then call the second program

%occur(myStruct) = 1;
Callp EdtCstRtn(MyStruct:Struct1);

Here is the code from the Called program:

DCstRtnParm PR ExtPgm('@EDTCSTRTN')
DPlistPR Like(PlistParm)
DPlist1PR Like(Plist1)
DCstRtnParm PI
DPlistPI Like(PlistParm)
DPlist1PI Like(Plist1)

DPlistParm e ds ExtName(EDTCSTPF)
D occurs(500)
D based(p_PlistParm)
DPlist1 e ds ExtName(EDTCSTHDR)
D based(p_Plist1)

/free
p_PlistParm = %addr(PlistPI);
p_Plist1 = %addr(Plist1PI);

... do NOT EVAL one to the other...
... simply access PlistParm as a normal MODS.

Note that MyStruct and PlistPArm *must* have an identical definition
for
this to work properly, and you MUST pass the first occurrence to the
called program, or unpredictable results will occur. The basing
pointers only force the two copies of the DS to overlay the same
block
of bytes in the computers memory. If they don't match, you might end
up
reading data that belongs to other variables, or you might end up
getting corrupt data, etc.

Anyone who makes changes to your program will need to understand the
mechanism and how to ensure that the definitions are always the same,
or
they'll have unpredictable results, too. Unlike option (A), the
compiler won't provide any safeguards.

Method (b) also precludes the use of CONST, and therefore makes it
harder to provide good encapsulation. (Though, I don't know if this
is
an input/output parameter or input only, though.)
--
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 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.