As an earlier respondent noted, you can use COBOL tables to build a
stack area, where the function or paragraph state and variables are
preserved by pushing them onto the stack, then popping them from the
stack when that particular instance of the function is returned to.
The code will look strange to someone not used to seeing stacks
implemented in COBOL, but if you must preserve variables and pass
variables while recusively calling functions/paragraphs, this is the
best way I know to handle it. (Either that or write a small C coded
stub that's called...)
Mel Bartels
Programmer/Analyst
Goshen Admin
Willamette Industries, Inc.
85647 Hwy 99 South
Eugene, OR 97405
Phone 541-744-4600
Fax 541-988-5570
mailto: [log in to unmask]
----------
From: Therm-O-Link [SMTP:[log in to unmask]]
Sent: Thursday, March 05, 1998 8:45 AM
To: HP3000-L
Cc: SIGCOBOL-L
Subject: [COBOL] Recursion Supported?
Glenn Cole wrote:
>(I tend to think of this as "circular calls" rather than recursion,
>but that may be just me.)
>I verified that this calling sequence (A->B->A) is supported
>without warning of any kind, and it works just fine.
I rewrote the program to recursively perform a paragraph, and it
worked just fine. Now, paragraph A performs paragraph B, which
may perform paragraph A again. I haven't tried a case where
A would perform B during the second perform, leading to a third
perform of A. The really hard part is keeping track of what
chain you're traversing in the data set, and resetting the
chain back to the original when you've finished the second
chain. I suppose you could table-ize the chain pointers so
that a number of different levels of B-O-M could be traversed
without difficulty (from the program's perspective, not the
programmer's!). Luckily we only have a three-tier (at most)
B-O-M.
Thanks to all who responded.
Jim Phillips Manager of Information
Systems
E-Mail: [log in to unmask] Therm-O-Link, Inc.
Phone: (330) 527-2124 P. O. Box 285
Fax: (330) 527-2123 Garrettsville, Ohio 44231
|