|
Not sure how efficient this has to be but if speed is important then maintaining a separate array > based on dynamic memory for each ODO structure and then copying the data to a single large > character field once the length of the individual components is known. Then pass that character > field.
On Aug 15, 2017, at 3:30 AM, Joni V. <joni_vanderheijden@xxxxxxxxxxx> wrote:
Hello Jon,
If I understoord correctly, in COBOL, the memory space for the occurences is allocated, but it's done at run-time. This means they can define the table length using a variable, like the number of elements we passed to them. But I'm not certain that memory space is the issue here, more the physical space the structure occupies in a datastructure.
With the DEPENDING ON in COBOL they allow the fields after the dynamically sized table to be correctly positioned, after only the used occurences.
With the Dim keyword in RPG we have no such option, since it's value should be a constant. The fields following the array are always positioned after the maximum number of elements.
You also asked for a bit more detail.The operations are defined using base types of the framework of the other system, in their framework the lists are dynamically sized. Data is passed along as plain text, so we mimic the layout of the operation's data types using RPG data types.
I'm aware of dynamic memory for arrays, but don't see how this would have avoided having to set the position of each element after the dynamic array in the interface datastructure.
Can I use the based keyword on an element of a datastructure?
I'm guessing allocating extra memory for the array would have no impact on the position of the elements after the array, since it's actually allocating the memory for the pointer on which it's based. No?
Forgive me my inexperience, I'm still quite new to this. And thanks for your help / time.
Kind regards,
Joni
________________________________
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxx> on behalf of Jon Paris <jon.paris@xxxxxxxxxxxxxx>
Sent: Monday, August 14, 2017 21:46
To: Rpg400 Rpg400-L
Subject: Re: Dynamic array in interface
I am not aware of any plans to support dynamic arrays in RPG (which is what you are effectively asking for) but you are mistaken in your comparison with COBOL.
Yes there is an Occurs Depending On (ODO) option, but the full amount of memory space is always allocated so I don't see how it makes a difference. I have passed structures from RPG with the same layout as a COBOL ODO and it works fine so I'm having trouble understanding your issue.
Also, if you are passing this as a parm from RPG to COBOL only the pointer to the first byte ever gets passed so the actual size of the structure is irrelevant anyway.
You could always use dynamic memory for the array in RPG - If you can give a bit more detail about how the data is passed we might be able to help more with how to implement such an option.
Jon Paris
www.partner400.com<http://www.partner400.com>
www.SystemiDeveloper.com<http://www.SystemiDeveloper.com<http://www.SystemiDeveloper.com<http://www.SystemiDeveloper.com>>
On Aug 14, 2017, at 3:50 AM, Joni V. <joni_vanderheijden@xxxxxxxxxxx> wrote:
Hello everyone,
I was setting up an interface to an other system, and had a little RPG issue.
I had an interface passing data based on a datastructure which can contain arrays. For example:
Dcl-Ds tInterfaceDs Template Qualified;
NbElements Zoned(3);
LsElements LikeDs(tElementDs) Dim(10);
SwImportant Ind;
End-Ds;
Now in RPG, even if only 3 elements are filled in the array, the space for the empty elements will be reserved. The value of SwImportant will be positioned after the 10 elements. So the address of the switch is at: address datastructure + size(NbElements) + 10 * size(LsElements)
On the other side of the interface they have dynamic list types. So when only 3 elements are filled they only expect 3 elements. They value of the switch is expected after the 3 elements. So the address of the switch is at: address datastructure + size(NbElements) + 3 * size(LsElements)
This interface is still being used for other systems, and they had a component which mapped each list to a dynamic list (in COBOL). This component could not be added to our architecture.
For most interfaces, we differentiated between the two interfaces (the old system and the new system without the mapping).
When there was only one list, I moved it to the end of the datastructure, since it doesn't trigger issues if the empty elements are at the end of the data being passed.
But if there was more than one list in a certain datastructure, we had to resort to mapping the data to the correct position by manipulating their address pointers. This works great, but lowers readability a lot.
This whole approach seemed a bit forced, and I got the feeling that there should be a better approach. How would you have approached this issue?
Are there any plans for dynamic arrays, allowing variables in the Dim keyword like they do for COBOL in OCCURS ... DEPENDING ON?
Thanks in advance,
Joni
--
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: 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.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link: http://amzn.to/2dEadiD
--
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: 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.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link: http://amzn.to/2dEadiD
--
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: 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.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link: http://amzn.to/2dEadiD
As an Amazon Associate we earn from qualifying purchases.
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.