The answer is to use LOCAL-STORAGE in place of WORKING-STORAGE for the 
recursive routine.  LOCAL-STORAGE is obtained on entry to the subprogram and is 
(as the name implies) local to the current CALL level.

Unfortunately, it also means the recursive part must be in a 
separately-compiled program, since as you researched recursive programs can't 
be nested in the implementations that we have.

HTH

Peter

-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf 
Of John McKown
Sent: Tuesday, July 30, 2013 9:46 AM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: COBOL ? - emulating recursive PERFORM statement

I had a programmer as whether a PERFORM could be recursive. The answer is
"No". I even tried to explain why. But he says that if he could do it, it
would save some "really messy" coding. So I thought that I'd ask here if
anyone has ever heard of a way to do something which would be similar to a
recursive PERFORM. I've always heard that recursion can be replaced with a
stack and iterative programming. But I've not come up with a way to do
this, nicely, in COBOL. Perhaps that is the "messiness" to which the
programmer was referring. Perhaps because COBOL doesn't implement stacks
either. So a stack must be implemented with a array and a
current-index-value variable, perhaps defined as INDEXED BY.

I was looking into using nested programs which were recursive. But that
turns out to not be possible. RECURSIVE programs can't have nested
programs. And nested programs can't be RECURSIVE.
--

This message and any attachments are intended only for the use of the addressee 
and may contain information that is privileged and confidential. If the reader 
of the message is not the intended recipient or an authorized representative of 
the intended recipient, you are hereby notified that any dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please notify us immediately by e-mail and delete the message and any 
attachments from your system.

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to