FINDREP a short string with longer without overwriting next column

本小妞迷上赌 提交于 2019-12-24 17:39:11

问题


So I have a set of data such as this:

mxyzd1    0000015000
mxyzd2    0000016000 
xyzmd5823 0000017000

I need to use dfsort to get this data:

123xyzd1  0000015000
123xyzd2  0000016000 
xyz123d5820000017000

So what I mean is: replace all character 'm' by '123' without overwriting the second column, so truncate data before you get to the second column (which starts at pos 11).

So far I've been able to replace the data but can't prevent all of my data of getting shifted, this is my code so far:

SYSIN    DATA  *                                                 
 SORT FIELDS=(1,1,CH,A)                                          
 OUTREC FINDREP=(IN=C'm',OUT=C'123',STARTPOS=1,ENDPOS=10,
 MAXLEN=20,OVERRUN=TRUNC,SHIFT=YES)                      
         DATAEND                                                 
*        

回答1:


The problem you are facing is that all data on a record will be shifted to the right if the FINDREP change increases the length, and to the left if the FINDREP change decreases the length. Any change in the length of the changed data affects the entire record. You have discovered this yourself.

To put that another way, FINDREP does not know about fields (columns are best termed something like that) it only knows about records, even when it is looking only at a portion of the record, changes in length reflect on the rest of the record.

There is no way to write just a FINDREP to avoid this.

  OPTION COPY
  INREC IFTHEN=(WHEN=INIT,
                 OVERLAY=(21:1,10)),
        IFTHEN=(WHEN=INIT,
                 FINDREP=(IN=C'm',
                          OUT=C'123',
                          STARTPOS=21)),
        IFTHEN=(WHEN=INIT,
                 BUILD=(21,10,
                        11,10))

This will put the data from 1,10 into a temporary extension to the record. It will do the FINDREP on the temporary extension only. Then it will take the first 10 bytes of the extension and put them into position one for a length of 10.



来源:https://stackoverflow.com/questions/31381336/findrep-a-short-string-with-longer-without-overwriting-next-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!