View previous topic :: View next topic
|
Author |
Message |
sriuri
New User
Joined: 17 Nov 2006 Posts: 2 Location: India
|
|
|
|
Hi,
I am changing a cobol program to PL/1 program and I came across this problem.
01 A.
05 B
OCCURS 1 TO 20000
DEPENDING ON X INDEXED BY Y.
The Cobol program has an array where the length of the array is increased as per the need during the run time . i.e when an input message is read the value of X is incremented by 1 and the input msg copied on to the array(which essentially means that we are not preallocating fixed amount of memory to the array ).
Please can you let me know if we have a corresponding PL/1 implementation.
Tried googling but didnt find any thing.
Any help much appreciated. |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Read about "controlled" and "allocate" in the :
Enterprise PL/I for z/OS Language Reference |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
I don't know COBOL well enough, but to say that the array is increased at run-time seems to be utterly impossible, as the storage management would be very complex.
In PL/I you would used BASED / REFER, which from a performance point of view, used to be absolutely shyte (it's a lot better nowadays). Simply create an array of 20,000 elements and keep track of the position of the last element of the array, much easier and unbeatable, performance-wise.
Don't even think about using controlled to make resizeable arrays. |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Quote: |
Don't even think about using controlled to make resizeable arrays.
|
Hello Prino,
can you tell me why? |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
Using CTL to make a re-sizeable array, i.e. one of the OCCURS DEPENDING will require you to allocate a second one, making, in principle, the first one inaccessible in the stack of controlled storage, which means that you will have to have a based array/structure to retain access, and use that to copy the contents to the new one. You will not be able to free the original one, and that may cause problems.
In other words, CTL is used to create an array of a size that is only known at run-time, eg as held in the header record of a file, or obtained via a "SECELT COUNT(*)" DB2 statement and once it's allocated you do not touch the size any more.[/list] |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Thanks Prino,
so the next sequence of actions is not working ? :
get the message length
allocate the array with the length
get next message length
same or less than previous length ---> use the array
if not free the array and allocate one with the new length |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
Of course that's working, but that's not really a resizable array, more a series of arrays. The simple fact is, once you've allocated a CTL array, you cannot resize it, other than by a free + alloc.
A BASED REFER array is dynamic and, not tested, I think HBOUND, LBOUND, DIM will return the current bounds and extent. |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Quote: |
but that's not really a resizable array, more a series of arrays
|
I agree totally with that.
Thanks for the explanation. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
The OCCURS DEPENDING ON in Cobol is nothing to do with any "dynamic" sizing. The compiler allocates storage for the maximum value. The actual value in the ODO field is just the "current length" of the table. If it "dynamically" goes beyond the maximum value at runtime, it will go BANG! with SSRANGE, or it will look at/trash the storage in the following data definition. If you are lucky, the latter will cause a noticeable problem. If unlucky, the latter will go unnoticed for some period of time requiring some feverish "problem determination"/"impact analysis" at a future date. |
|
Back to top |
|
|
sriuri
New User
Joined: 17 Nov 2006 Posts: 2 Location: India
|
|
|
|
Thank you all for your replies.I tried to see what Bill was suggesting and it turns out that it does allocate memory for the maximum value and X is only to hold the length of the table.
Thanks once again! |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Thanks for letting us know. |
|
Back to top |
|
|
|