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

Calling Subprogram only once.


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

New User


Joined: 26 May 2007
Posts: 70
Location: chennai

PostPosted: Sun Mar 06, 2011 8:37 am
Reply with quote

Hi,

I have a program say Program XYZ will be called numerous times in production from main program say program ABC.

In sub program XYZ, to increase performance, Values are selected from DB2 database tables and stored in an internal program array.

I have a requirement where the array should be only populated once. That is, logic in the program should be such that it detects whether the values have already been populated in the array and should remain static each time the program is called.

How to do in PL/1 ?

Kindly Help. Thanks.
Back to top
View user's profile Send private message
prino

Senior Member


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

PostPosted: Sun Mar 06, 2011 12:49 pm
Reply with quote

Code:
 abc: proc options(main) reorder;
   dcl array (.....);
   dcl xyz entry;
 
   call xyz(array);

   do i = 1 to 10000000;
     /* use values from array */
   end;
 end abc;


Sheesh, was that so difficult?
Back to top
View user's profile Send private message
venuhunev

New User


Joined: 26 May 2007
Posts: 70
Location: chennai

PostPosted: Sun Mar 06, 2011 10:56 pm
Reply with quote

Hi Prino,

Thnx for your reply.

Your code shows that xyz is called once and array value is fetched and used only once in main program.

But my question is, ABC calls XYZ in loop and Array is populated from DB2 tables and used in XYZ It should not be populated in all loops, only once inside the sub program.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon Mar 07, 2011 12:10 am
Reply with quote

to clarify Robert post

since we do not know the details of the subroutine, You were given a general hint...

split the subroutine in two parts

part one to be called outside of the loop to initialize the array,

inside the loop just use the array already filled ( Robert snippet)
or call the subroutine doing the process-only part!
Back to top
View user's profile Send private message
prino

Senior Member


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

PostPosted: Mon Mar 07, 2011 12:15 am
Reply with quote

Your requirements are as clear as mud, not surprisingly... My solution matches them.

Can you tell me why my solution does not match your requirements as given in the first post of the thread?
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon Mar 07, 2011 12:19 am
Reply with quote

the TS is confused... he seems to believe that the i is the index of the array !
Back to top
View user's profile Send private message
venuhunev

New User


Joined: 26 May 2007
Posts: 70
Location: chennai

PostPosted: Mon Mar 07, 2011 5:40 pm
Reply with quote

ok.

I ll make my requirements very clear.

Code:
 abc: proc options(main) reorder;
   dcl array (.....);
   dcl xyz entry;
    do i = 1 to 10000000;
        call xyz(array);
   end;
 end abc;


Code:

xyz: proc

step1 - declare the array
step2 - populate the array only once frm the respective db2 tables.
step3 - perform other operations
step4 - return

end xyz;


Step 2 should be executed only once even if ABC calls XYZ 1000000 times.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Mar 07, 2011 6:02 pm
Reply with quote

regardless of programming language:
step two (2) should in addition to populating the array, set a flag.
then subsequent calls to the module would check the flag, and if set, skip step2.

you can declare a flag, initialized to 'no' or 'off' or 'notset'.-
end of step2, set the flag to 'yes', 'on', 'set'.

if you can't make that work, you can't keep the table populated between calls.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon Mar 07, 2011 7:18 pm
Reply with quote

Quote:
Step 2 should be executed only once even if ABC calls XYZ 1000000 times.


that' s what we kept telling You, call the subroutine to fill the array once before entering the <outer> loop

if You cannot understand such a simple suggestion You do not have a plece in IT icon_evil.gif
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Mon Mar 07, 2011 9:07 pm
Reply with quote

I am not a PLI programmer, but my favourite way of approaching this problem is to code the subroutine to behave as follows:

Code:
Search array.
If not found
   fetch from DB2
   store value in array
endif
Return value from array.
 

This avoids having to load the entire array the first time the subroutine is called. I have often found that many processes use only a small percentage of the possible array elements, so you might as well only load the ones actually needed. Your mileage will vary.
Back to top
View user's profile Send private message
prino

Senior Member


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

PostPosted: Mon Mar 07, 2011 9:17 pm
Reply with quote

And by keeping the array "small", you can improve the efficiency even more by using a simple LRU algorithm to keep the most used values in it. (With "small" empirically defined based on the cost of going to DB2 vs the cost of looping through the array)

In PL/I you could conceivably even sort the array in a separate thread and use a binary search on it, although that might increase CPU use too much...
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Mon Mar 07, 2011 9:50 pm
Reply with quote

So much depends on the specifics:
The TYPE of table lookup (direct vs binary vs sequential) can be influenced by a number of factors, including:

1) the class of the table argument (numeric, alphanumeric) and
2) the range of possible argument values

For example: if the arguments are numeric and the range is from 1 to 1000, it may make more sense to store and access table entries using the argument itself as a subscript into the table.

3) the frequency distribution of argument

For example: if the argument is state-code and you are processing payroll data, it may make sense to populate the table in descending order by the number of employees in each state and perform a sequential search.

4) the maximum number of arguments possible vs
5) the average number of arguments accessed

For example: if there are 5 million possible argument values, but the average number accessed in a given run is only 5,000, then it may make sense to create a "sparse" array, in which only actually used arguments are stored (for future reference) rather than all 5 million. In some cases, it may make sense to "pre-scan" the input to normalize the actual argument values that will be used, and build the lookup table for just those arguments.

6) The order of the input arguments

For example, if the input is pre-sorted in ascending argument value, then it may make sense to not have a TABLE at all - as each search is initiated check to see if the argument matches a stored entry - if it does, you already have the result; if it has changed, retrieve the appropriate result, and save the argument and result for the next search.
Back to top
View user's profile Send private message
prino

Senior Member


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

PostPosted: Mon Mar 07, 2011 10:06 pm
Reply with quote

Even a mixed approach is possible when the distribution is extremely skewed, as, for example here in Belgium, with members of Belgian health insurers. About 97% of their members are Belgian, 1% are Dutch and French and the rest is the rest. By doing a linear search on B/NL/F followed by a binary search on the rest, processing was sped up enormously.

The old situation? Would you believe it? An unsorted array, with B somewhere past the middle...
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Mon Mar 07, 2011 10:19 pm
Reply with quote

Prino, Ronald, thanks for rescuing a thread that wasn't going anywhere. Sometimes even a "dumb" question can lead to an interesting discussion. icon_smile.gif
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


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

PostPosted: Mon Mar 07, 2011 11:38 pm
Reply with quote

Belgium is a not existing country. Half of it is french, half of it is dutch.
So how about distribution?
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 Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Calling Java method from batch COBOL ... COBOL Programming 5
No new posts Calling an Open C library function in... CICS 1
No new posts How to go into a subprogram in IBM De... IBM Tools 5
No new posts calling a JCl inside a JCL JCL & VSAM 3
Search our Forums:

Back to Top