Search code examples
sortingmainframejcl

Replace HEX value with another HEX value in variable-length dataset using SORT/ICEMAN


I have a VB file were can a HEX value ‘0D25’ come in any position from 1 to 20 (values from 21 position should not be changed). This need to be replaced with HEX value ‘4040’.

Input:

----+----1----+----2----+----3----+----4----+
0000/12345678  566  @(#)@0000/12345678  566  
FFFF6FFFFFFFF02FFF44B475BFFFF6FFFFFFFF02FFF02
0000112345678D5566005DBD50000112345678D5566D5

Expected output:

----+----1----+----2----+----3----+----4----+
0000/12345678  566  @(#)@0000/12345678  566  
FFFF6FFFFFFFF44FFF44B475BFFFF6FFFFFFFF02FFF02
000011234567800566005DBD50000112345678D5566D5

I was using SORT with below control card.

SORT FIELDS=COPY                                     
OUTREC FIELDS=(1,4,5,20,CHANGE=(20,X'0D25',X'4040'), 
                        NOMATCH=(5,20),              
               21)           

                    

Solution

  • CHANGE= does not work the way you think it does. It does a lookup at only the specified position. It then replaces with either the replacement character(s), or with the NOMATCH= character(s) in exactly the length specified as the first sub-parm of CHANGE= (20 in your case).

    FINDREP= searches for the specified character(s) in each position, and replaces with the replacement character(s). You limit to the part of the record to be inspected with the STARTPOS=, and ENDPOS= keywords, resp.

    In your case the following statement should do what you want:

    OUTREC FINDREP=(INOUT=(X'0D25',X'4040'),STARTPOS=5,ENDPOS=24)