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






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

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.