Highlighted
Absent Member.
Absent Member.
3207 views

Copy/Replacing statement

Jump to solution

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).
   

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Copy/Replacing statement

Jump to solution

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.

View solution in original post

0 Likes
1 Reply
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Copy/Replacing statement

Jump to solution

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.

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.