Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Dynamically increasing Array size?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler
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    Post subject: Dynamically increasing Array size?
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: 2422
Location: Netherlands, Amstelveen

PostPosted: Tue Dec 11, 2012 3:23 pm    Post subject:
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

Active Member


Joined: 07 Feb 2009
Posts: 984
Location: Oostende, Belgium

PostPosted: Tue Dec 11, 2012 4:01 pm    Post subject:
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: 2422
Location: Netherlands, Amstelveen

PostPosted: Tue Dec 11, 2012 4:15 pm    Post subject:
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

Active Member


Joined: 07 Feb 2009
Posts: 984
Location: Oostende, Belgium

PostPosted: Tue Dec 11, 2012 4:59 pm    Post subject:
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: 2422
Location: Netherlands, Amstelveen

PostPosted: Tue Dec 11, 2012 5:06 pm    Post subject:
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

Active Member


Joined: 07 Feb 2009
Posts: 984
Location: Oostende, Belgium

PostPosted: Tue Dec 11, 2012 5:12 pm    Post subject:
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: 2422
Location: Netherlands, Amstelveen

PostPosted: Tue Dec 11, 2012 5:16 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Tue Dec 11, 2012 7:59 pm    Post subject: Reply to: Dynamically increasing Array size?
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Wed Dec 12, 2012 3:11 pm    Post subject: Reply to: Dynamically increasing Array size?
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    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Increase the screen size after split mistah kurtz TSO/ISPF 2 Fri Sep 02, 2016 6:39 pm
No new posts how to DYNAMICALLY write sort cond to... mohamedmubee COBOL Programming 13 Fri Aug 26, 2016 11:46 pm
No new posts PL/I: opening file w/ dynamically det... Sam Dodgers PL/I & Assembler 6 Wed Jul 27, 2016 4:05 pm
No new posts Unstring list of values into an array. Roshnii COBOL Programming 8 Mon Jun 27, 2016 6:25 pm
No new posts ALTER of an IDMS AREA with NEW/OLD pa... Awanti IDMS/ADSO 2 Mon Mar 14, 2016 10:01 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us