PLI Dynamic array creation



IBM's cross-platform compiler PL/I for MVS, VM & VSE, OS/390 and Enterprise PL/I for z/OS

PLI Dynamic array creation

Postby prasob1234 » Tue Jul 26, 2011 12:04 pm

On PLI/XML Parser:
I am using dynamic array concept to declare array element G_AREA,
G_AREA is a value that we get from an xml,i dnt know how much time the G_AREA occur's in the xml(it is defined as unbounded in xsd).
But i can find the occurence at the end of program(After processing is complete)

is there any way to allocate a dynamic array based on it's occurence?

Now i am using code:

DCL 1 G_AREA (*) CTL,
3 G_FC CHAR(2),
3 GCODE CHAR(2),
3 GNAME CHAR(50),
3 GE_FC CHAR(2),
3 GPARENT CHAR(50);

ALLOCATE G_AREA(100)


But if i get G_AREA,no of instances >100,it will be a pbm.

So pls let me know if i can do it somehow in PLI
prasob1234
 
Posts: 4
Joined: Mon Jul 25, 2011 1:34 pm
Has thanked: 0 time
Been thanked: 0 time

Re: PLI Dynamic array creation

Postby enrico-sorichetti » Tue Jul 26, 2011 12:35 pm

is there any way to allocate a dynamic array based on it's occurence?

ALLOCATE G_AREA(100)


the question as posed is just a waste of time for everybody!

for any operating system, for any language, for any format of storage allocation
You must know the amount requested before/when performing the allocation PERIOD

if You know the number of occurrences beforehand why not take advantage of it
ALLOCATE takes a variable as parameter as in
 ****** ***************************** 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 ****************************
 


tested and working
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: PLI Dynamic array creation

Postby prasob1234 » Tue Jul 26, 2011 1:05 pm

Hello enrico...

Thanks for ur quick response.But in the question i have clearly mentioned that the occurence will be known only at end of program.If the occurrences vary ,the array must be handling it.Pls read question completely before u reply.
If u know the space before allocating ,wat is the pbm in using it in pgm.
I have tried using REFER option,but it's abending.
prasob1234
 
Posts: 4
Joined: Mon Jul 25, 2011 1:34 pm
Has thanked: 0 time
Been thanked: 0 time

Re: PLI Dynamic array creation

Postby enrico-sorichetti » Tue Jul 26, 2011 1:43 pm

Thanks for ur quick response.But in the question i have clearly mentioned that the occurence will be known only at end of program.

now I strongly confirm that we are wasting time on a stupid question :evil:
So pls let me know if i can do it somehow in PLI

not in PL/I nor in any other language existing or to be written yet
a time warp based programming language has not been discovered yet,

before asking this kind of question ask Yourself first and meditate a bit more on Your logic please :geek:
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: PLI Dynamic array creation

Postby prasob1234 » Tue Jul 26, 2011 3:01 pm

Enricho,

IF you are so sure we cannot handle it ,pls expain me the below code .
I have seen this is many programs.

3 COUNTZ FIXED DECIMAL(1,0),
2 G_AREA (100 REFER (COUNTZ)) CHAR(10);

If G_AREA exceeds 100,it will REFER to countz variable and extends dynamically

if u r not aware of how it is to be handled ,better u dont give such stupid remarks.Is better you concentrate on something else.


Can anyone explain if it works out?
prasob1234
 
Posts: 4
Joined: Mon Jul 25, 2011 1:34 pm
Has thanked: 0 time
Been thanked: 0 time

Re: PLI Dynamic array creation

Postby enrico-sorichetti » Tue Jul 26, 2011 3:49 pm

first of all learn to spell properly people' s names!
if You do not know the good manners just go back to the cave where You belong :evil:

second did You care to read the manual about the refer option ... ?

http://publibz.boulder.ibm.com/cgi-bin/ ... T#FIRSTHIT

...
2 Y (L refer (X)),
...
When STR is allocated, the upper bound is set to the current value of L which is assigned to X.
...


and L must be filled before the allocation...
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: PLI Dynamic array creation

Postby dick scherrer » Tue Jul 26, 2011 8:48 pm

Hello,

But in the question i have clearly mentioned that the occurence will be known only at end of program.
Then you clearly must seek an alternative approach. . .

One possibility is that the process needs to be split - one part to determine what you are working with and the other to actually do the work after the limits are determined. It should be rather simple to do this and not a strain. . . The end of one process would be the start of the other and the value(s) would be known. To let something like this "stop" your effort is not a good sign. . .

Possibly, there is something i misunderstand. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: PLI Dynamic array creation

Postby Akatsukami » Tue Jul 26, 2011 11:39 pm

prasob1234 wrote:On PLI/XML Parser:
I am using dynamic array concept to declare array element G_AREA [...] is there any way to allocate a dynamic array based on it's occurence?

No. As Dr. Sorichetti indicates, you cannot cause information to propagate backward through time. Indeed, no one can. Either divide the process into two parts so that the number of elements in the array is determined before you allocate it, as Mr. Scherrer suggests, or else use a linked list or similar construct.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: PLI Dynamic array creation

Postby enrico-sorichetti » Wed Jul 27, 2011 12:00 am

I was going to suggest a linked list too, but probably there might be a better solution
just by analyzing a bit more the requirement and the origin of the source data
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: PLI Dynamic array creation

Postby prasob1234 » Wed Jul 27, 2011 11:09 am

Hello,

Let me explain the requirement clearly:

I am using a PLISAXC(BUILTIN fn) Parser to parse an xml document in a PLI Program.This xml will be input to PLI Program.The elements in the XML is defined such that it can occur N number of times.
For example consider G_AREA ,This is an element in xml,and it can occur N number of times in xml,but the occurence is unknown.

I need to parse it first,store the values of G_AREA in an array and later use it for processing.
The problem in using array is that if i am declaring G_AREA(100) and later in the input xml the occurence exceed more than 100,then i need to edit the souce code(-tat is not a correct method).

There are two solution which i have in my mind:
1.Allocate maximum value for G_AREA array and use it in program
2.If it's not possible using any method,then i need to parse it twice,first time to know the occurence and parse again and allocate a dynamic array for the same.

Let me know if anything else is possible.

Sorry Dr. Sorichetti for spelling ur name wrongly,and thanks for the link.


Pls let me know if it's not clear....
prasob1234
 
Posts: 4
Joined: Mon Jul 25, 2011 1:34 pm
Has thanked: 0 time
Been thanked: 0 time

Next

Return to PL/I

 


  • Related topics
    Replies
    Views
    Last post