ACUCOBOL-GT allows a program to call itself, directly or indirectly. A CALL statement that attempts to call an active program is termed a recursive call.
To use recursive calls, you must set the configuration variable RECURSION to 1 (on, true, yes). The default setting for RECURSION is 0 (off, false, no), which disallows recursive calls.
When you allow recursive calls, an active program may be called again. This causes a new copy of the program to be loaded into memory and executed, as if it were the first call of that program. Files and data described in that program are local to each copy of the program.
More specifically, the runtime assigns a recursion level to each recursively called program. The first time a program is called, it is assigned a recursion level of 0. If that program is still active and it is called again, it receives a recursion level of 1. The recursion level is incremented by 1 for each active copy of the same program.
When you call a program at a specific recursion level for the first time, it is freshly loaded from disk and its Working-Storage data items are given their initial values as defined by their VALUE clauses. Subsequent calls to a program at the same recursion level will find the files and data left in the same state that the program had when it last exited.
Files and data items are distinct between different recursion levels.
When you CANCEL a recursively called program, all of its inactive copies are removed from memory. Active copies are left alone. Subsequent calls to any of the canceled recursion levels will reload the program from disk and reinitialize the files and data items.
If you need to share data between different active copies of the same program, you can pass this data through the Linkage Section. Alternatively, you can share both files and data items by declaring them as EXTERNAL items. Yet another option is the RECURSION_DATA_GLOBAL configuration option.
The runtime system shares the program code for recursively called programs. Thus, while each recursion level has its own set of data, there is only one copy of the Procedure Division code in memory, regardless of how many active copies of the program there are. The runtime system does not, however, share overlays. Each copy of the program in memory has its own overlay area.