Monday, September 26, 2011

COBOL: COPY REPLACING

I have a copybook, in which i need to change the first three characters of the variables. All the copy book variables start with M1E. I need to change it to I1E.

For eg. the variables look like this
M1ENAME PIC X(20)
M1EADD PIC X(30)


and I need it like this  

I1ENAME PIC X(20)
I1EADD PIC X(30)


The copy command I used is

copy copybook replacing ==M1E== BY ==I1E== .
But it's not working..
So what can be done?


Solution
The REPLACING option is WORD oriented not SUB-STRING oriented. If you want to do SUB-STRING replacement, you have to use colons as prefix/suffix in the copybook ( e.g. :M1E:NAME, :M1E:ADD, etc. ) and specify REPLACING ==:M1E:== by ==I1E==.

Otherwise we have to say :
REPLACING M1ENAME BY I1ENAME
         M1EADD BY I1EADD....etc 
(i.e. use the entire WORD. But this won't be feasible, when we have too many fields.)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.