I need to replace a string of characters with another in a dataset. Want to do it using JCL.
The file has field separators that look like this --> "," <-- I want this string carrying dblqt comma dblqt to be replaced with just a single | (pipe) character. The rec length is 400 plus. The string appears after every field in the record as a separator.
I planned to use Fileaid but that can only handle 255 chars at a time. To overcome that OI can split the record into multiple statements. But then I may actually split it somewhere in between "," thereby not replacing it.
Did you try doing it with the SORT utility? Using the CHANGE and NOMATCH parameter of the OUTREC statement, you should be able to change one string to another provided you know the exact positions of the strings.
The CHANGE subparameter changes an input field to a replacement constant in the reformatted output record if the input field equals a search constant. The input field remains unchanged on the input side.
NOMATCH indicates how SyncSort should respond if the input field
does not match a search constant. If NOMATCH is not specified and no search constant matches the input field, sort processing will terminate with an error message.
Actually this "," is a field terminator - so its position is not fixed - depending on length of the field it can be anywhere. It is a VB dataset. With fields like Name address etc - so based on size - the "," can be anywhere
The data format seems like a good candidate for a SAS program or for your own in-house written program, or maybe an ISPF EDIT session run in batch mode.
What do you consider to be a valid programming language and/or utility when you say "using JCL"?
Thanks for all your help - I did find a way to take care of this using fileaid in JCL. I wanted to avoid writing a SAS, COBOL, EASYTRIEVE etc...
Posting it here just in case someone needs it.
//STEP01 EXEC PGM=FILEAID
//SYSPRINT DD SYSOUT=*
//SYSLIST DD SYSOUT=*
//DD01 DD DISP=SHR,DSN=A.B.C.D
//DD01O DD DSN=X.Y,Z,
// DISP=(NEW,CATLG,DELETE),
// UNIT=DISK,SPACE=(CYL,(800,800),RLSE)
//* (TO,LENGTH,FROM)
//SYSIN DD *
$$DD01 COPYALL EDIT=(1,5,X'7F',C''), <-- Replaces the first " with null
EDITALL=(6,0,X'7F6B7F',C'|'), <--Replaces "," with |
EDITALL=(400,0,X'7F',C''), <--Replaces last " with null
OUT=0
/*
x'7F' is hex for "
x'6B' is hex for ,
1,5 - means starting from 1 - next 5 bytes
6,0 - means starting from 1 upto end of record
400,0 - means starting from 400 upto end of record
I had a " in the begining and end of record and "," after every field. And had to remove the first and last double quotes and replace "," with |.
Thanx for sharing the resolution of your prob w/us.
I just hope everyone out there follows your example and either provides feedback on a solution offered or shares their own solution w/the rest of us in the forum.