Menu ▾ ▴

#1261 Some issues with the CDF statement REPLACE

GC 3.x
open
nobody
None
5 - default
2026-10-05
2026-10-03
No

I’ve noticed some strange behavior with the attached sample program compiled as follows.

cobc testreplace.cob -x -T TESTREPLACE.TXT -Xref --save-temps

As shown in the listing, the REPLACE CDF statement does not modify some but it modifiy other lines.
This is likely an issue specific to the listing itself.
The " .i " file (saved with--save-tempsoption) is correct.
Compilation completes without errors, and the program runs correctly.

It seems that REPLACE does not consider the text enclosed within the two quotation marks or parentesis.
Even when using reference modification in last MOVE , the replacement takes place, but the closing parenthesis is lost.
Is this behavior correct ?

3 Attachments

Discussion

  • Simon Sobisch

    Simon Sobisch - 2026-10-03

    Are the results in the postprocessed listing different from the preprocessed (--save-temps generates that as .i) file?

    Which GnuCOBOL version did you use (if 3.2, I think we had fixes in with the listing and the REPLACE code).

     
  • Eugenio Di Lorenzo

    • Attachments has changed:

    Diff:

    --- old
    +++ new
    @@ -1,3 +1,2 @@
    -TESTREPLACE.COB (1.6 kB; application/octet-stream)
     TESTREPLACE.TXT (3.7 kB; text/plain)
     testreplace.i (952 Bytes; application/octet-stream)
    
     
  • Eugenio Di Lorenzo

    • Attachments has changed:

    Diff:

    --- old
    +++ new
    @@ -1,2 +1 @@
    -TESTREPLACE.TXT (3.7 kB; text/plain)
     testreplace.i (952 Bytes; application/octet-stream)
    
     
  • Eugenio Di Lorenzo

    • Attachments has changed:

    Diff:

    --- old
    +++ new
    @@ -1 +0,0 @@
    -testreplace.i (952 Bytes; application/octet-stream)
    
     
  • Eugenio Di Lorenzo

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -2,10 +2,10 @@
    
     `cobc testreplace.cob -x -T TESTREPLACE.TXT -Xref --save-temps`
    
    -As shown in the listing, the `REPLACE` CDF statement does not modify lines 28 and 29 but it modifiy other lines. es 31, 32, 33, 34. This is likely an issue specific to the listing itself.
    +As shown in the listing, the `REPLACE` CDF statement does not modify some but it modifiy other lines.
    
    + This is likely an issue specific to the listing itself.
     The " .i " file (saved with` --save-temps `option)  is correct.
     Compilation completes without errors, and the program runs correctly.
    
    -Also at row 36 of the listing the `REPLACE`  CDF statement does not work.
    -It seems that `REPLACE` does not consider the text enclosed within the two quotation marks.
    +It seems that `REPLACE` does not consider the text enclosed within the two quotation marks or parentesis.
     Is this behavior correct ?
    
    • Attachments has changed:

    Diff:

    --- old
    +++ new
    @@ -0,0 +1,3 @@
    +LISTING.TXT (2.7 kB; text/plain)
    +TESTREPLACE.COB (1.9 kB; application/octet-stream)
    +testreplace.i (1.1 kB; application/octet-stream)
    
     
  • Eugenio Di Lorenzo

    The gc99fed2.i listing obtained using the --save-temps option is correct; all REPLACE substitutions were performed properly.

    However, the listing obtained using the -T option shows discrepancies, as the value that was supposed to be replaced remains in certain cases.
    I noticed that the replacement does not occur if the value was enclosed in double quotes or within parentheses.
    Even when using reference modification in last MOVE , the replacement takes place, but the closing parenthesis is lost.
    I am attaching a new version of the .COB program, the .TXT listing file, and the .i file to the first post of this ticket.

    I am using the compiler included with the SuperBOL installation, which is as follows:

    cobc (GnuCOBOL) 3.3-dev.0
    Copyright (C) 2023 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart
    Built     Mar 06 2024 10:59:48
    Packaged  Mar 06 2024 09:58:52 UTC
    C version (MinGW) "13.2.0"
    
    build information
    build environment        : x86_64-pc-mingw64
    CC                       : gcc
    C version                : (MinGW) "13.2.0"
    CPPFLAGS                 : 
    CFLAGS                   : -O2 -pipe -finline-functions -fsigned-char
                               -Wall -Wwrite-strings -Wmissing-prototypes
                               -Wno-format-y2k
    LD                       : ld.exe
    LDFLAGS                  : 
    
    GnuCOBOL information
    COB_CC                   : gcc
      env: COB_CC            : C:\Users\eugen\AppData\Local\GnuCOBOL\mingw64\bin\gcc.exe
    COB_CFLAGS               : -pipe -Wno-unused -fsigned-char
                               -Wno-pointer-sign
      env: COB_CFLAGS        : -I
                               "C:\Users\eugen\AppData\Local\GnuCOBOL\include"
                               -pipe -Wno-unused -fsigned-char
                               -Wno-pointer-sign
    COB_DEBUG_FLAGS          : -ggdb3 -fasynchronous-unwind-tables
    COB_LDFLAGS              : 
      env: COB_LDFLAGS       : -L "C:\Users\eugen\AppData\Local\GnuCOBOL\lib"
    COB_LIBS                 : -lcob
    COB_CONFIG_DIR           : config
      env: COB_CONFIG_DIR    : C:\Users\eugen\AppData\Local\GnuCOBOL\config
    COB_COPY_DIR             : copy
      env: COB_COPY_DIR      : C:\Users\eugen\AppData\Local\GnuCOBOL\copy
    COB_MSG_FORMAT           : GCC
    COB_OBJECT_EXT           : o
    COB_MODULE_EXT           : dll
    COB_EXE_EXT              : exe
    64bit-mode               : yes
    BINARY-C-LONG            : 4 bytes
    endianness               : little-endian
    native EBCDIC            : no
    extended screen I/O      : ncursesw
    variable file format     : 0
    sequential file handler  : built-in
    indexed file handler     : BDB
    mathematical library     : GMP
    XML library              : libxml2
    JSON library             : cjson
    
     

    Last edit: Eugenio Di Lorenzo 2026-10-05
  • Eugenio Di Lorenzo

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -8,4 +8,5 @@
     Compilation completes without errors, and the program runs correctly.
    
     It seems that `REPLACE` does not consider the text enclosed within the two quotation marks or parentesis.
    +Even when using reference modification in last MOVE , the replacement takes place, but the closing parenthesis is lost.
     Is this behavior correct ?
    
     

Log in to post a comment.