FINDREP较长的短字符串,不会覆盖下一列 [英] FINDREP a short string with longer without overwriting next column

查看:153
本文介绍了FINDREP较长的短字符串,不会覆盖下一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一组这样的数据:

So I have a set of data such as this:

mxyzd1    0000015000
mxyzd2    0000016000 
xyzmd5823 0000017000

我需要使用dfsort来获取此数据:

I need to use dfsort to get this data:

123xyzd1  0000015000
123xyzd2  0000016000 
xyz123d5820000017000

所以我的意思是:用'123'替换所有字符'm'而不覆盖第二列,因此在到达第二列(从pos 11开始)之前截断数据.

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                                                 
*        

推荐答案

您面临的问题是,如果FINDREP更改增加了长度,记录中的所有数据将向右移,如果FINDREP更改减小了长度,则向左移动.更改后的数据长度的任何更改都会影响整个记录.您自己发现了这个.

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.

换句话说,FINDREP不了解字段(最好将列称为这样的字段),它仅了解记录,即使仅查看记录的一部分,长度的变化也会反映其余部分记录.

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.

没有办法只编写一个FINDREP来避免这种情况.

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

这会将来自1,10的数据放入记录的临时扩展名.它将仅对临时扩展名执行FINDREP.然后,将使用扩展名的前10个字节并将其放置在位置1中,长度为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.

这篇关于FINDREP较长的短字符串,不会覆盖下一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆