Menu

I can't get the Copy Replacing to work

2020-09-26
2020-09-28
  • Graham Knight

    Graham Knight - 2020-09-26

    I'm trying to replace to beginning of the varibles in a copybook with the replacing option on the copy statement but it does seem to work. What am I doing wrong?

    Attached is the copybook and an extract from the program listing. What I was expecting was the first part of varible name to be replaced but it seems that the whole varible has been replaced. The program has a clean compile accept for two warnings about "warning: line not terminated by a newline" at the end of the copybook inclusion.

    COPYEXAM.CPY is the copybook.

    The following is the compiler output.

    000042           01 WS-SCR003.
    000043              COPY COPYEXAM REPLACING ==:OO:==
    000044                   BY ==SCROO3==.
    000001C       * start of copybook
    000002C       *
    000003C
    000004C            02 SCROO3 PIC X(9)
    000005C                                    VALUE ALL " ".
    000006C            02 SCROO3 PIC X(50)
    000007C                                    VALUE ALL " ".
    000008C            02 SCROO3 PIC X(100)
    000009C                                    VALUE ALL " ".
    000010C            02 SCROO3 PIC X(100)
    000011C                                    VALUE ALL " ".
    000012C       * end of copybook
    
     

    Last edit: Simon Sobisch 2020-09-26
    • Ralph Linkletter

      I would suggest trying "(" and ")" instead of the ":"
      The syntax below works as expected.

      05  (TAG12345)-RECFM             PIC  X(04). 
         COPY 'MVSGETCT.CPY' REPLACING ==(TAG12345)== BY ==GETCT1==.  
      

      Although the specification implies either will work.
      "Because many of the separators have special significance when processing a COPY statement, the values that can be used for delimiting part of a text word in this way are limited to the parenthesis and colon symbols."

       

      Last edit: Ralph Linkletter 2020-09-26
    • Brian Tiffin

      Brian Tiffin - 2020-09-27

      Works here. But I did re-save the COPYEXAM.CPY with vim after download to get rid of the no terminating new-line warning. VIm adds a final newline.

      ::cobolfree
      prompt$ cobc -E copytry.cob 
      #line 1 "copytry.cob"
       identification division.
       program-id. sample.
      
       data division.
       working-storage section.
       01 ws-scr003.
      
      
      #line 1 "COPYEXAM.CPY"
      
      
      
       02 SCR003-SCR002-O01 PIC X(9)
       VALUE ALL " ".
       02 SCR003-SCR002-O02 PIC X(50)
       VALUE ALL " ".
       02 SCR003-SCR002-O03 PIC X(100)
       VALUE ALL " ".
       02 SCR003-SCR002-O04 PIC X(100)
       VALUE ALL " ".
      
      #line 8 "copytry.cob"
      
      
       procedure division.
       sample-main.
       display ws-scr003
       goback.
       end program sample.
      
      prompt$ cobc --version
      cobc (GnuCOBOL) 3.1-dev.0
      ...
      
      Given
             01 ws-scr003.
                COPY COPYEXAM REPLACING ==:OO:==
                     BY ==SCR003==.
      

      I'd look to see if any stray unicode / extraneous bytes slipped in to any of the source files.

      Cheers,
      Blue

       
  • Mickey White

    Mickey White - 2020-09-26

    did you try putting both in single quotes or double qoutes ?

     

    Last edit: Mickey White 2020-09-26
  • Vincent (Bryan) Coen

    Following on from Mickey post try doing :

         COPY COPYEXAM REPLACING ":OO:"
                     BY "SCROO3".
    
    
                     That said, I would have thought that your usage should work !!!
    
    
                     Please always specify version and platform  i.e., v3.1 dev-0 and Linux
    
                     etc.
    
     
  • Graham Knight

    Graham Knight - 2020-09-27

    Using quotes gives a syntax error.

    Sorry but I'm using GnuCOBOL 3.1-rc1 (30Jun2020) with MinGW binaries
    (GCC 6.3.0, PDcurses 4.1.99, GMP 6.2.0, VBISAM 2.0.1)
    on win 10.

     
  • Graham Knight

    Graham Knight - 2020-09-28

    Hi everyone,

    I have found a way to make it work byi using the LEADING with the REPLACING. :-)

    000038 01 WS-SCR002.
    000039 COPY COPYEXAM REPLACING LEADING ==OO== BY ==SCROO2==.
    000001C * start of copybook
    000002C *
    000003C
    000004C 02 SCROO2-SCR002-O01 PIC X(9)
    000005C VALUE ALL " ".
    000006C 02 SCROO2-SCR002-O02 PIC X(50)
    000007C VALUE ALL " ".
    000008C 02 SCROO2-SCR002-O03 PIC X(100)
    000009C VALUE ALL " ".
    000010C 02 SCROO2-SCR002-O04 PIC X(100)
    000011C VALUE ALL " ".
    000012C * end of copybook

     

Anonymous
Anonymous

Add attachments
Cancel