[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [open-cobol-list] Recursive sequential file input?
From: |
Brian Tiffin |
Subject: |
Re: [open-cobol-list] Recursive sequential file input? |
Date: |
Sun, 04 Mar 2012 23:03:35 -0500 |
User-agent: |
Opera Mail/11.61 (Linux) |
On Fri, 02 Mar 2012 14:58:48 -0500, Fred Mobach <address@hidden> wrote:
Hello,
Some information about recursive programming in COBOL found on the web.
That encouraged me to test if it will also work on file input [1]. So I
wrote a small program / subroutine with some testfiles in one directory
(121 lines of code) which are available at
http://data.mobach.nl/opencobol/recursivetest/recursiveprog.tgz
The test program needs argument1 (= filename for input), calls a
subroutine with that name in its argument. The subroutine tries to read
that primary file, shows with display messages how it proceeds and
tries to recursively call itself with filenames found the primary file.
Console output example:
address@hidden:~/cob-idx/testrecurive> ./recursiveprog testrecursiv1
File to process: testrecursiv1
Sub: to process testrecursiv1
text: #empty
text: testrecursiv2
Next file to process: testrecursiv2
Sub: to process
recursiveprog.cob:94: libcob: File does not exist (STATUS = 35)
File : 'infile'
Environment:
OpenCobol : cobc (OpenCOBOL) 1.1.0
OS : GNU/Linux (opensuse 12.1 ) with kernel version 3.1.0-1.2
Question: is one of the INITIAL/COMMON options in the PROGRAM-ID needed
at top of the recursive option there or is it inpossible to reuse the
memory needed for an input file?
[1] This test is intended to check if it's possible in OpenCobol to read
a source program with nested COPY statements.
All that is needed is to put ws-namefound into LOCAL-STORAGE SECTION.
One line fix to
working-storage section.
01 program-namex pic x(0015) value "recursivesub".
01 programversionx pic x(0008) value "0.0.1".
01 programcompiledx pic x(0010) value "02-03-2012".
01 filler.
03 rec-length-in pic 9(05) comp.
03 ws-out-nbr pic 9(05) comp value 0.
03 ws-out-data.
05 ws-out-byte pic x(0001) occurs 248.
03 filler redefines ws-out-data.
05 ws-out-ident pic x(0001).
05 ws-out-text pic x(0247).
03 filler redefines ws-out-data.
05 ws-out-source pic x(0048).
05 filler pic x(0100).
01 ws-switches.
03 sw-eof-input pic x(0001) value low-values.
88 eof-input value high-value.
local-storage section.
01 ws-namefound pic x(0128).
linkage section.
01 actual-cmdlinearg1 pic x(0128) value spaces.
Gives
address@hidden testrecurive]$ cobc -x -g -debug recursiveprog.cob
address@hidden testrecurive]$ ./recursiveprog testrecursiv1
File to process: testrecursiv1
Sub: to process testrecursiv1
text: #empty
text: testrecursiv2
Next file to process: testrecursiv2
Sub: to process testrecursiv2
text: #empty
text: testrecursiv3
Next file to process: testrecursiv3
Sub: to process testrecursiv3
text: #empty
text: #unused line
text: #last
recursiveprog.cob:104: libcob: File not open (STATUS = 42) File : 'infile'
so there are still issues with the code flow, but not disappearing
working-storage problems.
Cheers,
Brian