Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

call a subroutine from within a subprocedure

Status
Not open for further replies.

GAORR

Programmer
Nov 22, 2001
48
CA
Is it possible to call a subroutine (exsr xxxxx) from within a subprocedure (callp). I know it won't compile when the subroutine is defined 'outside' of the subprocedure, but it will compile and so far seems to execute ok if the subroutine is defined 'inside' the subprocedure.

Assuming it works, would it be considered acceptable RPG code?

Thanks for the advice
 
Subroutines are only called within the RPG program. As far as I know there is no external way of calling a subroutines like other language. The only way I have done this before is to create a program which contains only subroutines. You invoke the subroutines by using parameter listing of some sort. Of course this parameters are depending on which subroutines you are calling. You have to include the name of the subroutine in the parameter listing.
 
If I understand your question to be: Can a subprocedure contain subroutines? Sure; no problem.

 
that sounds a bit scary and hell to maintain.


the thought really never came to mind of even trying it. Structure your subs as they should be and things will be much easier for you to maintain and future programmers in mind as well that may have to maintain the code.



___________________________________________________________________
[sub]
onpnt.com
SELECT * FROM programmers WHERE clue > 0
(0 row(s) affected) -->faq333-3811
[/sub]

 
I'm not sure it would be considered good style but it works fine. I write almost exclusivly in /free now but embedded SQL requires fixed-type specs. Rather than drop in and out of /free, I exsr from /free and place my fixed code in the subroutine.

Kyle
 
For maintainability, just put the subroutines in a /COPY member, and copy them into your subprocedures. (You just have to compile all the procedures again, but if you use a CMS, it's usually done automatically).

Me transmitte sursum, Caledoni!.

 
Thanks all to your answers/suggestions.
It is appreciated.
 
Coding in /free and using embedded SQL can be an ugly read. I like the suggestion of putting the fixed format code into a subroutine, however, that won't work when using a cursor doing the equivelant of:

setll
read
dow not %eof
<process>
read
enddo

The record fetch has to be part of the loop.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top