Menu

#927 COPY/REPLACE issues

GC 3.x
open
None
5 - default
2026-08-26
2023-10-30
No

While building a utility to manage the ISAM files in our big app I had
occasion to implement the CDF functions COPY, COPY/REPLACE, and REPLACE.
These functions are still in need of attention. My observations:

COPY <file>
  • works with no issues either in code or the listing
COPY <file> REPLACE ==field1== BY ==field2==.
COPY <file> REPLACE LEADING ==field1== BY ==field2==.
  • never works
COPY <file> REPLACE ==field1== BY ==field2==
END-COPY.
  • cobc throws syntax error
REPLACE <file> REPLACE ==field1== BY ==field2==.
  • works on whole words only
  • code is always correctly modified
  • listing code may or may not reflect the modified code
REPLACE <file> REPLACE LEADING ==field1== BY ==field2==.
  • replaces partial words correctly
  • listing code may or may not reflect the modified code
REPLACE <file> REPLACE LEADING ==field1== BY ==field2==,
               REPLACE LEADING ==field3== BY ==field4==.
  • never works

The program wherein I use these CDF statements has about 20 files defined
as source file definitions and the same number of target files. The
target file definitions used the same copybook as the source but with a
REPLACE CDF ie:

REPLACE <file> REPLACE LEADING ==field1== BY ==field2==.
COPY <copybook>.
REPLACE OFF.</copybook></file>

This always modified the code correctly for the compiler. However the
modified code was not always reflected in the listings. The listings may
reflect the modified code correctly through a couple of REPLACE functions
and then the next REPLACE did not. Strangely the next REPLACE might show
in the listing correctly.

There has some commentary about these issues in the discussion blog but
the best I can tell these issues are still at large. I reviewed the
change log but did not see where any code may have been applied. Since
I have a solution this is just a FYI.

I enclose a short program and a copybook for it. Several of the CDF
combinations are used with additional notes in the source code. If one
desires some code can be edited out and then run through 'cobc' to note
any issues. The program as is does not compile.

enc: test-replace.cbl test-replace-area.cpy

cobc -v:
cobc (GnuCOBOL) 3.2-dev.0
Built Feb 28 2023 14:36:32 Packaged Feb 28 2023 20:33:33 UTC
C version "9.4.0"
r5080

2 Attachments

Discussion

  • Vincent (Bryan) Coen

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,4 +1,3 @@
    -
     While building a utility to manage the ISAM files in our big app I had
     occasion to implement the CDF functions COPY, COPY/REPLACE, and REPLACE.
     These functions are still in need of attention.  My observations:
    
    • assigned_to: Vincent (Bryan) Coen --> Simon Sobisch
     
  • Fabrice Le Fessant

    There is no bug here:

    • In the first error that you point to, you are trying to do a partial replacement without using LEADING or TRAILING, it is not supposed to work in COBOL in general
    • In the last error that you point to, you are trying to modify some text within a string, which is not possible in COBOL in general, as the string is interpreted as a single token.
    • Other replacements are performed correctly when I check your files with the generated .i file with -g.

    I think this bug can be closed as not a bug.

     

Log in to post a comment.