View previous topic :: View next topic
Author
Message
bbharathiraj Warnings : 1 New User Joined: 26 Oct 2006Posts: 50 Location: Chennai
Hi ,
Could any one help me to achieve the following requirement thru SORT?
I have a flat file (Recfm=FB,LrecL=80) with the following data.
1001010
1002 010
1002 999
1004333
1004666
1005 010
1005 999
1023754
The output file should have the following data
1002010
1002999
1005010
1005999
i.e, If the first 4 bytes (Ex:1002) is having the same value with its next record (The 5 to 7th byte should have ?010? and ?999? for these 2 same records) then I need to extract these records into the output file.
Bharathiraj
Back to top
Frank Yaeger DFSORT Developer Joined: 15 Feb 2005Posts: 7129 Location: San Jose, CA
Assuming you won't have duplicate records which both have '010' or both have '999', you can use this DFSORT job to do what you asked for:
Code:
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=... input file
//OUT DD DSN=... output file
//TOOLIN DD *
SELECT FROM(IN) TO(OUT) ON(1,4,CH) ALLDUPS USING(CTL1)
/*
//CTL1CNTL DD *
INCLUDE COND=(5,3,SS,EQ,C'010,999')
/*
Back to top
bbharathiraj Warnings : 1 New User Joined: 26 Oct 2006Posts: 50 Location: Chennai
Thanks Frank. Am I right If I consider the operator ?SS? as ?String Search? ?
I have one more question here.
Lets have a input file (Recfm=FB,Lrecl=80) and the input file having the following records.
1002010
1002999
1002010
1004333
1004666
1005010
1005999
1005010
1023754
1007010
1007999
And I have to create the below output file.
1002999
1002010
1005999
1005010
(i.e) If the input records having the duplicate records on position 1 to 4, then I need to extract only the 2 records (same value on 1 to 4th byte) were the second record should have the value ?010? in 5 to 7th byte and it should be followed by ?999? on its previous record.
For example, in the given input file the first 3 records having the same value on first 4 bytes. But I need to extract only the second and third record since the third record having the value ?010? on position 5 to 7 and also it?s followed by ?999?.
Note: Red one should be eliminated.
Shall we do this kind of compare in DFSORT? If so, could you help me out?
Back to top
Frank Yaeger DFSORT Developer Joined: 15 Feb 2005Posts: 7129 Location: San Jose, CA
Yes, SS is substring search.
Your new requirement is rather tricky, but I believe this DFSORT/ICETOOL job will work:
Code:
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//SORTIN DD DSN=... input file (FB/80)
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//T2 DD DSN=&&T2,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//CON DD DSN=*.T2,VOL=REF=*.T2,DISP=(OLD,PASS)
// DD DSN=*.T1,VOL=REF=*.T1,DISP=(OLD,PASS)
//OUT DD DSN=... output file (FB/80)
//TOOLIN DD *
COPY FROM(IN) USING(CTL1)
SPLICE FROM(T1) TO(T2) ON(1,4,CH) ON(84,8,ZD) -
WITHEACH WITH(81,3) USING(CTL2)
SPLICE FROM(CON) TO(OUT) ON(1,4,CH) ON(84,8,ZD) -
WITHALL WITH(1,80) WITH(108,1) USING(CTL3)
/*
//CTL1CNTL DD *
INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:5,3,84:SEQNUM,8,ZD,
100:SEQNUM,8,ZD,RESTART=(5,3),108:C'VV')),
IFTHEN=(WHEN=(5,3,CH,EQ,C'999'),
OVERLAY=(84:SEQNUM,8,ZD)),
IFTHEN=(WHEN=NONE,
OVERLAY=(92:SEQNUM,8,ZD,
84:84,8,ZD,SUB,92,8,ZD,M11,LENGTH=8))
OUTFIL FNAMES=T1,OMIT=(5,3,CH,EQ,C'010',AND,100,8,ZD,GT,+1)
/*
//CTL2CNTL DD *
OUTFIL FNAMES=T2,
INCLUDE=(5,3,CH,EQ,C'999',AND,81,3,CH,EQ,C'010'),
OVERLAY=(108:C'BB')
/*
//CTL3CNTL DD *
INCLUDE COND=(5,3,SS,EQ,C'999,010')
OUTFIL FNAMES=OUT,INCLUDE=(108,2,CH,EQ,C'VB'),
BUILD=(1,80)
/*
For a thorough test, I used this input data:
Code:
1002010 R01
1002999 R02
1002010 R03
1003999 R04
1003999 R05
1003010 R06
1004333 R07
1004666 R08
1005010 R09
1005999 R10
1005010 R11
1023754 R12
1007010 R13
1007999 R14
1008010 R15
1008010 R16
1009999 R17
1010999 R18
1010010 R19
1010010 R20
1010010 R21
1012999 R22
1012555 R23
1012010 R24
and the job produced this output data:
Code:
1002999 R02
1002010 R03
1003999 R05
1003010 R06
1005999 R10
1005010 R11
1010999 R18
1010010 R19
Back to top
bbharathiraj Warnings : 1 New User Joined: 26 Oct 2006Posts: 50 Location: Chennai
Thanks Frank. You have given a wondeful solution. Thanks a lot
Back to top
Please enable JavaScript!