Page 1 of 1

Builtin Function to get total size of a dynamic array?

PostPosted: Fri May 29, 2015 2:28 pm
by sathyanandak
Hello Forum,

I was try to find if any builtin function to get current size of all elements in total of a dynamic array allocated using controlled storage class. I am searching for builtin function to reduce LOC!

Re: Builtin Function to get total size of a dynamic array?

PostPosted: Fri May 29, 2015 3:26 pm
by enrico-sorichetti
You will find no such function ...

when You code something like
 ****** ***************************** Top of Data ******************************
 000001  Alloc:                                                                 
 000002      Proc Options(Main);                                               
 000003      dcl pliretc builtin;                                               
 000004      dcl 1 arr(*)  ctl,                                                 
 000005          5 num fixed bin(31) ;                                         
 000006      dcl dim fixed bin(31) init(200);                                   
 000007      allocate arr(dim);                                                 
 000008      call pliretc(0) ;                                                 
 000009      End;                                                               
 ****** **************************** Bottom of Data ****************************


once pl1 has allocated the <array>
to keep track of the max indexes values is up to You

I am searching for builtin function to reduce LOC!


if LOC as in common jargon means Lines Of Code
how will the knowledge of the % used for controlled things
reduce the LOC ???

Re: Builtin Function to get total size of a dynamic array?

PostPosted: Fri May 29, 2015 3:42 pm
by BillyBoyo
Because, enrico, function domagic() can hide literally several lines of code. Thus reducing the overall LOC. domagic() uses lots more CPU, but the bean-counters are concerned about LOC :-)

Re: Builtin Function to get total size of a dynamic array?

PostPosted: Fri May 29, 2015 4:20 pm
by enrico-sorichetti
as usual it a problem of the carrot and the stick ...
a high LOC will show a high productivity
but the same will make the maintenance budget forecast larger

Re: Builtin Function to get total size of a dynamic array?

PostPosted: Sat May 30, 2015 3:57 am
by prino
sathyanandak wrote:I was try to find if any builtin function to get current size of all elements in total of a dynamic array allocated using controlled storage class. I am searching for builtin function to reduce LOC!

enrico-sorichetti wrote:You will find no such function ...

{snip}

once pl1 has allocated the <array>
to keep track of the max indexes values is up to You

CSTG (aka CURRENTSTORAGE, or as it's now called, CURRENTSIZE) will tell you, and if you

dcl array(i:j) fixed bin (31) ctl;
dcl (i,j) fixed bin (31);

i = 42;
j = 53:

alloc array;


the LBOUND, HBOUND and DIM builtins will all return the correct values. PL/I internally keeps track of every bound, dimension, length, etc of controlled variables, the programmer just uses the required builtins to find them!

Re: Builtin Function to get total size of a dynamic array?

PostPosted: Sat May 30, 2015 10:56 am
by enrico-sorichetti
Thanks Robert,

:oops: I read too quickly , misunderstood the question and misworded the reply ...

I had inferred that the TS wanted to know not how much was allocated but how much was used out of the allocated area
so I should have written ( for the original way I saw things )
to keep track of the max indexes values REACHED is up to You

instead of
to keep track of the max indexes values is up to You


anyway the comment about LOC is still valid

here is a snippet according to the revised understanding
( did not even have to write it, it was already there in my set of samples )

 ****** ***************************** Top of Data ******************************
 000001  Alloc:
 000002      Proc Options(Main);
 000003      dcl pliretc builtin;
 000004      dcl (i,j) fixed bin(31);
 000005      dcl a(i:j) fixed bin(31) ctl;
 000006      i=11; j=23;
 000007      allocate a;
 000008      put skip list(lbound(a,1));
 000009      put skip list(hbound(a,1));
 000010      put skip list(cstg(a));
 000011      put skip list(dim(a));
 000012      call pliretc(0) ;
 000013      End;
 ****** **************************** Bottom of Data ****************************


********************************* TOP OF DATA **********************************
            11
            23
            52
            13
******************************** BOTTOM OF DATA ********************************

Re: Builtin Function to get total size of a dynamic array?

PostPosted: Fri Jul 17, 2015 12:02 pm
by sathyanandak
Thanks Enrico :) I used your first approach using counter to then use length info and pointer to be passed to calling program for processing.