Copy/Replacing statement

We have a copy/replacing statement where our intent is to change the 01 level to an 02 level.

Here is the statement we are using, note the space before and after the 01 and 02 values.

Copy "PrmPolcy.fd" replacing leading ==MP==     By ==VPPINew==,
                                        leading ==PRM==    By ==VPPINew==,
                                        leading == 01 == By == 02 ==.
The copybook begins like this

       01  PRMPOLCY-RECORD.                  03  MP-KEY.               05 MPPOLYR.                  10  MPPOLY-YY                        PIC X(02).                                     10  MPPOLY-MM                        PIC X(01).                                  05 MPPREFIX                             PIC X(02).               05 MPPOLNO                              PIC X(05).

This is what gets created. The field MPPOLY-MM  defined as PIC X(01) gets changed to a Pic X(02) which is incorrect.
It changed all fields that were Pic X(01) To X(02). How can we prevent this from happening.

02 VPPINewPOLCY-RECORD.
03 VPPINew-KEY.
05 VPPINewPOLYR.
10 VPPINewPOLY-YY PIC X(02).
10 VPPINewPOLY-MM PIC X(02).
05 VPPINewPREFIX PIC X(02).
05 VPPINewPOLNO PIC X(05).
   

  • Verified Answer

    During processing of COPY REPLACING the PICTURE string is parsed just like any other text in the input source, so that for instance the PICTURE string associated with MPPOLY-MM is broken up into separate tokens 'X', '(', '01', ')'.  In terms of COPY REPLACING, it is therefore correct that the 01 is replaced in this context as these are the leading (and only) characters in this token.

    Possibly this looks a bit clunky but the only way I can see of achieving what you want is something like:

              Copy "PrmPolcy.fd" replacing leading ==MP==     By ==VPPINew==,

                                           leading ==PRM==    By ==VPPINew==,

                                                   ==(01)==   By ==(01)==,

                                                   == 01 == By == 02 ==.

    Since the COPY REPLACING code will use the first matching alternative, the extra replacing branch ensures that the PICTURE strings are unchanged.  Of course, there could still be problems if the copied file happened to have a data item with 'VALUE 01', or any other use of 01 other than as a level number.