IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Dynamically increasing Array size?


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sriuri

New User


Joined: 17 Nov 2006
Posts: 2
Location: India

PostPosted: Tue Dec 11, 2012 3:01 pm
Reply with quote

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
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Tue Dec 11, 2012 3:23 pm
Reply with quote

Read about "controlled" and "allocate" in the :

Enterprise PL/I for z/OS Language Reference
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Tue Dec 11, 2012 4:01 pm
Reply with quote

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
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Tue Dec 11, 2012 4:15 pm
Reply with quote

Quote:

Don't even think about using controlled to make resizeable arrays.


Hello Prino,

can you tell me why?
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Tue Dec 11, 2012 4:59 pm
Reply with quote

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
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Tue Dec 11, 2012 5:06 pm
Reply with quote

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
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Tue Dec 11, 2012 5:12 pm
Reply with quote

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
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Tue Dec 11, 2012 5:16 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Dec 11, 2012 7:59 pm
Reply with quote

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
View user's profile Send private message
sriuri

New User


Joined: 17 Nov 2006
Posts: 2
Location: India

PostPosted: Wed Dec 12, 2012 3:00 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Dec 12, 2012 3:11 pm
Reply with quote

Thanks for letting us know.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Using Java/C/C++ to retrieve dataset ... Java & MQSeries 6
No new posts Find the size of a PS file before rea... COBOL Programming 13
No new posts Masking variable size field - min 10 ... DFSORT/ICETOOL 4
No new posts COBOL Ascending and descending sort n... COBOL Programming 5
Search our Forums:

Back to Top