|
View previous topic :: View next topic
|
| Author |
Message |
chitra_chaturvedi
New User

Joined: 24 Jul 2007 Posts: 18 Location: india
|
|
|
|
Hello,
I need to replace a value in my file based on certain condition. Can I accomplish this with sort
input is something like:
1L042009A1
1L042009C1
1L042009C1
1L042009C4
1L042009C4
1L042009E1
1L042009G1
1L042009G1
1L042009G1
if the value at the position 9 is same for consecutive records, the value at position 1 (which is '1') should be changed to '2' for the second record onwards
expected output
1L042009A1
1L042009C1
2L042009C1
1L042009C4
2L042009C4
1L042009E1
1L042009G1
2L042009G1
2L042009G1
Thanks for the help in advance! |
|
| Back to top |
|
 |
Frank Yaeger
DFSORT Developer

Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
In your expected output, why do you show the 4th record with a '1' instead of a '2'? Records 2-5 have a 'C' in position 9, so records 3-5 should have a '2' in position 1 - right?
According to your description, the expected output should be:
| Code: |
1L042009A1
1L042009C1
2L042009C1
2L042009C4
2L042009C4
1L042009E1
1L042009G1
2L042009G1
2L042009G1
|
If that's what you want, then here's a DFSORT job that will do it. I assumed your input file has RECFM=FB and LRECL=80, but the job can be changed appropriately for other attributes.
| Code: |
//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
1L042009A1
1L042009C1
1L042009C1
1L042009C4
1L042009C4
1L042009E1
1L042009G1
1L042009G1
1L042009G1
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC IFOUTLEN=80,
IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD,RESTART=(9,1))),
IFTHEN=(WHEN=(81,8,ZD,GT,1),OVERLAY=(1:C'2'))
/*
|
|
|
| Back to top |
|
 |
chitra_chaturvedi
New User

Joined: 24 Jul 2007 Posts: 18 Location: india
|
|
|
|
It was actually position 9 and 10 ( eg C1, C4 etc..). My apologies for incomplete information.
But it certainly works !!
Thankyou Frank..  |
|
| Back to top |
|
 |
Frank Yaeger
DFSORT Developer

Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
If it's 9 and 10, then the DFSORT control statements would be:
| Code: |
OPTION COPY
INREC IFOUTLEN=80,
IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD,RESTART=(9,2))),
IFTHEN=(WHEN=(81,8,ZD,GT,1),OVERLAY=(1:C'2'))
|
and SORTOUT would have:
| Code: |
1L042009A1
1L042009C1
2L042009C1
1L042009C4
2L042009C4
1L042009E1
1L042009G1
2L042009G1
2L042009G1
|
|
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|