MVSFORUMS.com A Community of and for MVS Professionals
View previous topic :: View next topic
Author
Message
jathampy Beginner Joined: 21 Dec 2007 Posts: 18 Topics: 7 Location: UK
Posted: Mon Oct 21, 2024 1:42 pm Post subject: Replace variable digits with zero
I am looking for a SORT to replace a numeric field that can vary between 1 and 11 digits with zero at same position
The first 4 character indicate record type. There are 5 other record types similar to 'GENE' where I need to replace non-zero numbers with zero.
Input :
Code:
GENE,1,bbbb,cccc,dddd,125.12,102220
GENE,12,bbbb,cccc,dddd,80.11,103450
GENE,123,bbbb,cccc,dddd,98.16,674532
GENE,1234,bbbb,cccc,dddd,89.87,665432
GENE,12345,bbbb,cccc,dddd,97.64,765431
GENE,123456,bbbb,cccc,dddd,54.32,108912
GENE,1234567,bbbb,cccc,dddd,43.22,543211
GENE,12345678,bbbb,cccc,dddd,12.19,904532
GENE,123456789,bbbb,cccc,dddd,9.85,652789
GENE,1234567890,bbbb,cccc,dddd,11.91,786512
GENE,12345678901,bbbb,cccc,dddd,888.66,367231
OTHE,xyx,gggggh,78.12
OTHE,xyz,ffuyyt,99.99
Output
Code:
GENE,0,bbbb,cccc,dddd,125.12,102220
GENE,00,bbbb,cccc,dddd,80.11,103450
GENE,000,bbbb,cccc,dddd,98.16,674532
GENE,0000,bbbb,cccc,dddd,89.87,665432
GENE,00000,bbbb,cccc,dddd,97.64,765431
GENE,000000,bbbb,cccc,dddd,54.32,108912
GENE,0000000,bbbb,cccc,dddd,43.22,543211
GENE,00000000,bbbb,cccc,dddd,12.19,904532
GENE,000000000,bbbb,cccc,dddd,9.85,652789
GENE,0000000000,bbbb,cccc,dddd,11.91,786512
GENE,00000000000,bbbb,cccc,dddd,888.66,367231
OTHE,xyx,gggggh,78.12
OTHE,xyz,ffuyyt,99.99
Can code multiple IFTHENs like
Code:
IFTHEN=(WHEN=(1,4,CH,EQ,C'GENE',AND,7,1,CH,EQ,C','),OVERLAY=(6:C'0')).
IFTHEN=(WHEN=(1,4,CH,EQ,C'GENE',AND,8,1,CH,EQ,C','),OVERLAY=(6:2C'0')) etc. to handle this.
Since there are 5 other record types similar to 'GENE' I have to use 50+ IF statements,
I can use PARSE something like this to split the record but then have to write logic to replace non-zero digits with zero.
Code:
INREC IFTHEN=(WHEN=(1,4,CH,EQ,C'GENE'),
PARSE=(%1=(ABSPOS=6,ENDBEFR=C',',FIXLEN=11),
%2=(FIXLEN=63)),
BUILD=(1,5,%1,%2)),
IFTHEN=(WHEN=NONE,BUILD=(1,80))
Appreciate any help on this.
Back to top
kolusu Site Admin Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Mon Oct 21, 2024 11:30 pm Post subject:
jathampy ,
It is quite simple to replace the variable contents. Here is an untested DFSORT JCL that will give you the desired results.
Code:
//SYSIN DD *
OPTION COPY
INREC IFOUTLEN=80,
** For all required types parse the contents and change to zero **
IFTHEN=(WHEN=(1,4,SS,EQ,C'GENE,ABCD,XXXX,YYYY,ZZZZ'),
PARSE=(%01=(ENDAT=C',',
FIXLEN=05),
%02=(ENDBEFR=C',',
FIXLEN=11),
%03=(FIXLEN=63)),
** build the temp record at position 81 **
OVERLAY=(81:%01,%02,C',',%03,
** Use CHANGE to replace the values to zeros **
86:86,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
87:87,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
88:88,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
89:89,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
90:90,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
91:91,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
92:92,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
93:93,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
94:94,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
95:95,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
96:96,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
** Now squeeze the contents to remove the spaces **
81:81,80,SQZ=(SHIFT=LEFT),
** Put back the replaced contents on to position 01 **
01:81,80))
/*
In case you are worried about losing the embedded spaces after the variable portion, you can use FINDREP to move strip off the trailing spaces like shown below
Code:
//SYSIN DD *
OPTION COPY
INREC IFOUTLEN=80,
** For all required types parse the contents and change to zero **
IFTHEN=(WHEN=(1,4,SS,EQ,C'GENE,ABCD,XXXX,YYYY,ZZZZ'),
PARSE=(%01=(ENDAT=C',',
FIXLEN=05),
%02=(ENDBEFR=C',',
FIXLEN=11),
%03=(FIXLEN=63)),
** build the temp record at position 81 **
OVERLAY=(81:%01,%02,C',',%03,
86:86,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
87:87,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
88:88,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
89:89,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
90:90,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
91:91,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
92:92,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
93:93,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
94:94,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
95:95,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0'),
96:96,01,CHANGE=(1,C' ',C' '),NOMATCH=(C'0')),
HIT=NEXT),
** Use FINDREP to strip off the trailing spaces for pos 86 to 96**
IFTHEN=(WHEN=(1,4,SS,EQ,C'GENE,ABCD,XXXX,YYYY,ZZZZ'),
FINDREP=(STARTPOS=86,ENDPOS=96,
INOUT=(C' ',C'')),HIT=NEXT),
** Put back the replaced contents on to position 01 **
IFTHEN=(WHEN=(1,4,SS,EQ,C'GENE,ABCD,XXXX,YYYY,ZZZZ'),
OVERLAY=(01:81,80))
//*
_________________ Kolusu
www.linkedin.com/in/kolusu
Back to top
jathampy Beginner Joined: 21 Dec 2007 Posts: 18 Topics: 7 Location: UK
Posted: Tue Oct 22, 2024 4:03 am Post subject:
Many Thanks Kolusu. I really appreciate your timely help. I admire your mainframe technical skills.
I am on leave Today and will try the SORT JCL Tomorrow.
Back to top
jathampy Beginner Joined: 21 Dec 2007 Posts: 18 Topics: 7 Location: UK
Posted: Wed Oct 23, 2024 1:40 pm Post subject:
I tested the SORT JCL and its working fine as expected. Many Thanks Kolusu for providing the solution
Back to top
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