View previous topic :: View next topic
Author
Message
sameetshetty New User Joined: 19 Jan 2007Posts: 11 Location: bangalore
Hi,
I have to sort and merge 2 files, but there is no way I can distinguish the detail records from the header and trailer records. Below is an example of how the file would look like
File 1
000000 (Header Record)
111111
333333
222222
000000
999999 (Trailer record)
File 2 (contains only detail record)
777777
999999
888888
and expected output file is
000000 (Header record from file 1)
000000
111111
222222
333333
777777
888888
999999
999999 (Trailer record from File 1)
Please note that the detail record can have records which are same as the header and trailer. As shown above, the detail record have 000000 and 999999 which are equal to the header and trailer respectively.
Could anyone please help me with this.
Back to top
shankar.v Active User Joined: 25 Jun 2007Posts: 196 Location: Bangalore
sameetshetty,
Please check with the following code for your requirement.
Code:
// EXEC PGM=ICETOOL
//DFSMSG DD SYSOUT=*
//TOOLMSG DD SYSOUT=*
//FILE1 DD DSN=FILE1,DISP=SHR
//FILE2 DD DSN=FILE2,DISP=SHR
//HEADER DD DSN=&&HEADER,DISP=(,PASS),SPACE=(TRK,(1,1))
//TRAILER DD DSN=&&TRAILER,DISP=(,PASS),SPACE=(TRK,(1,1))
//T1 DD DSN=&&T1,DISP=(,PASS),SPACE=(CYL,(5,5))
//T2 DD DSN=*.T1,DISP=(OLD,PASS),VOL=REF=*.T1
// DD DSN=*.FILE2,DISP=(OLD,PASS),VOL=REF=*.FILE2
//OUT DD DSN=OUT,DISP=(NEW,CATLG,DELETE),DCB=(FILE1),SPACE=(CYL,(5,5))
//TOOLIN DD *
COPY FROM(FILE1) TO(HEADER) USING(CTL1)
SORT FROM(FILE1) TO(TRAILER) USING(CTL2)
COPY FROM(HEADER) TO(OUT)
SORT FROM(T2) TO(OUT) USING(CTL3)
COPY FROM(TRAILER) TO(OUT)
/*
//CTL1CNTL DD *
OPTION STOPAFT=1
/*
//CTL2CNTL DD *
INREC OVERLAY=(81:SEQNUM,8,ZD)
SORT FIELDS=(81,8,ZD,D)
OUTFIL FNAMES=(TRAILER),STARTREC=1,ENDREC=1,OUTREC=(1,80)
OUTFIL FNAMES=(T1),OMIT=(81,8,ZD,EQ,1),STARTREC=2,OUTREC=(1,80)
/*
//CTL3CNTL DD *
SORT FIELDS=(1,6,CH,A)
/*
Back to top
Frank Yaeger DFSORT Developer Joined: 15 Feb 2005Posts: 7129 Location: San Jose, CA
sameetshetty,
Shankar's solution will NOT work unless you use a MOD data set for //OUT.
Here's another way to do what you asked for with DFSORT:
Code:
//S1 EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=... input file1 (FB/80)
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//SYM DD DSN=&&S1,UNIT=SYSDA,SPACE=(TRK,(1,1)),DISP=(,PASS)
//SYSIN DD *
OPTION COPY
OUTFIL FNAMES=T1,OVERLAY=(81:C' ',82:SEQNUM,8,ZD)
OUTFIL FNAMES=SYM,REMOVECC,NODETAIL,
BUILD=(80X),
TRAILER1=('LASTR,+',COUNT=(M11,LENGTH=8))
/*
//S2 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//SYMNAMES DD DSN=&&S1,DISP=(OLD,PASS)
//FILE2 DD DSN=... input file2 (FB/80)
//T1 DD DSN=&&T1,DISP=(OLD,PASS)
//T2 DD DSN=&&T2,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//T3 DD DSN=&&T3,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//TOOLIN DD *
SORT FROM(T1) TO(T2) USING(CTL1)
SORT FROM(FILE2) TO(T3) USING(CTL2)
/*
//CTL1CNTL DD *
INREC IFOUTLEN=81,
IFTHEN=(WHEN=INIT,OVERLAY=(81:C'1')),
IFTHEN=(WHEN=(82,8,ZD,EQ,+1),OVERLAY=(81:C'0')),
IFTHEN=(WHEN=(82,8,ZD,EQ,LASTR),OVERLAY=(81:C'2'))
OPTION EQUALS
SORT FIELDS=(81,1,CH,A,1,6,CH,A)
/*
//CTL2CNTL DD *
INREC BUILD=(1,80,81:C'1')
OPTION EQUALS
SORT FIELDS=(1,6,CH,A)
/*
//S3 EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN01 DD DSN=&&T2,DISP=(OLD,PASS)
//SORTIN02 DD DSN=&&T3,DISP=(OLD,PASS)
//SORTOUT DD DSN=... output file (FB/80)
//SYSIN DD *
OPTION EQUALS
MERGE FIELDS=(81,1,CH,A,1,6,CH,A)
OUTREC BUILD=(1,80)
/*
Back to top
Karthigaiselvan New User Joined: 11 Dec 2006Posts: 35 Location: India
Frank,
Looks awesome.
I'm looking to customizing this job for my requirement posted in the link http://www.ibmmainframes.com/viewtopic.php?t=26216
Though i am not sure if that's possible. Could you please think of any other solution for the requirement i posted in the above link? Thanks!
Back to top
Frank Yaeger DFSORT Developer Joined: 15 Feb 2005Posts: 7129 Location: San Jose, CA
I don't see how the requirement here and the requirement in your other post are related.
I posted a solution for the other requirement in that thread.
Back to top
Please enable JavaScript!