I want the contents of MAINFILE to be changed in such a way that,
MAINFILE after change will look like this:
RALP ANDREWS 31 XXX77 SAFASFS ASFASAS
TEST 200C002C MOVE ZEROS TO YYY888-UM CODE 32
CODE NUM: 11111111111111111111111111111111ZZZ4444444444
22 LAL122233 333 AJFAS 03 03 009.99 889.99 FREE
XXX77 SAFASFS ASFASAS
i.e.
1. whenever a XXX is encountered on any record in MAINFILE , the content after that, on the record should be replaced by first record on DATAFILE.
2. whenever a YYY is encountered on any record in MAINFILE , the content after that, on the record should be replaced by second record on DATAFILE.
3. whenever a ZZZ is encountered on any record in MAINFILE , the content after that on the record should be replaced by third record on DATAFILE.
How can this be achieved in REXX or any other utility ?
Last edited by naveen on Tue Jul 08, 2003 11:40 pm; edited 1 time in total
Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
Posted: Tue Jul 08, 2003 1:24 pm Post subject:
Naveen,
The following job using sort/file-aid job will give you the desired results. A brief explanation of the job.STEP010 takes in the datafile and creates 3 control cards one for each line.The control cards created in this step will be as follows:
Line1 file:
Naveen,
You're requirements are ambiguous. In each case you say "the content after that on the record should be replaced by the record on DATAFILE". By "the content after that on the record" do you mean everything up to column 80? If so, then example YYY is incorrect, since it didn't replace the trailing 11111s. If NOT so, then example XXX is incorrect, since the trailing asterisks disappeared. Which is it? Or which example is wrong?
Kolusu's solution will satisfy example YYY, but not example XXX.
Ron _________________ A computer once beat me at chess, but it was no match for me at kick boxing.
Ron,
Everything upto col. 80 should be replaced. Example ZZZ was incorrect. Trailing 1111s should also be replaced. I've coorected it in main post also.
Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
Posted: Wed Jul 09, 2003 5:55 am Post subject:
Naveen,
My solution was based upon your first post before correction. The first ,second and third line in the datafile are 18,14& 10 bytes respectively. So I used the same exact length for them. So if you need to overlay the contents after finding the required string change the length to 70 in all the control cards as follows:
Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
Posted: Wed Jul 09, 2003 8:01 pm Post subject:
Naveen,
The error you are getting is due to overlapping of outrec fields. The max length of the string you can replace is 68 bytes.So change the sort cards to the following.
Code:
SORT FIELDS=COPY
OUTFIL FNAMES=LINE1,ENDREC=1,
OUTREC=(C'$$DD01 COPY REPLALL=(1,0,C',X'7D',C'XXX',X'7D',C',',/,
C' C',X'7D',C'XXX',1,68,X'7D',C'),',80:X)
OUTFIL FNAMES=LINE2,STARTREC=2,ENDREC=2,
OUTREC=(C' REPLALL=(1,0,C',X'7D',C'YYY',X'7D',C',',/,
C' C',X'7D',C'YYY',1,68,X'7D',C'),',80:X)
OUTFIL FNAMES=LINE3,STARTREC=3,ENDREC=3,
OUTREC=(C' REPLALL=(1,0,C',X'7D',C'ZZZ',X'7D',C',',/,
C' C',X'7D',C'ZZZ',1,68,X'7D',C')',80:X)
Kolusu,
What changes will be required in Sysin card , If I want to include one more record in my DATAFILE which will correspond to say 'WWW' (in addition to 3 records which were corresponding to 'XXX','YYY', & 'ZZZ') thus making a total of 4 records in DATAFILE.
Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
Posted: Thu Jul 10, 2003 6:58 am Post subject:
Naveen,
Allocate another file LINE4 and code the control cards for line4 as follows. Also you need to add a comma for line 3 file as it is no longer the last line.
Code:
OUTFIL FNAMES=LINE3,STARTREC=3,ENDREC=3,
OUTREC=(C' REPLALL=(1,0,C',X'7D',C'ZZZ',X'7D',C',',/,
C' C',X'7D',C'ZZZ',1,68,X'7D',C'),',80:X)
OUTFIL FNAMES=LINE4,STARTREC=4,ENDREC=4,
OUTREC=(C' REPLALL=(1,0,C',X'7D',C'WWW',X'7D',C',',/,
C' C',X'7D',C'WWW',1,68,X'7D',C')',80:X)
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum