I've got an input file that looks like this:
HEADER1
DETAIL1
FOOTER1
HEADER2
DETAIL2
FOOTER2
HEADER3
DETAIL3
FOOTER3
HEADER4
DETAIL4
FOOTER4
I want to strip the detail records out into four different files. But there is no key field to distinguish them. Using COBOL it would be easy, but I need (want?) to use DFSORT.
So, how do I use the header record as some sort of trigger to tell DFSORT to use the next output file?
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
You specify multiple output files using one OUTFIL for each. There you state selection criteria (INCLUDE= or OMIT=, or SPLIT*, or several others for numbers of records).
Bill, that's the problem, there are no discernible selection criteria. There's nothing in the records that you could use to split them, They are all different layouts. Essentially it is four different files in one dataset.
There are four headers, four footers and lots of detail.
Start a count at 0. Whenever I get a header record add 1. The counter can be used to determine which file to write to. If 1 then File1, if 2 then File2 etc.
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
So, on INREC use IFTHEN=(WHEN=GROUP to identify your headers, and PUSH an ID onto an extension of the record.
The ID will be a sequence number per group of records, one for the first, two for the second, three for the third.
This then gives you your INCLUDE= for OUTFIL. position,length,one for the first OUTFIL, two for the second, where one and two are C'1' and C'2' assuming you really have four groups (this means you use a one-digit ID, which is ID=1).
Bill, thanks for the help. I've now got four jobs, each with the below statement but with different values for the INCLUDE= (the output goes direct into a set of Teradata Fastloads so I strip the header and footer). Maybe not the most efficient way of doing it (one job splitting the file and then four loads may be better) but it fits with our standard design pattern.
seems from Your last post that the header is just "HEADER" for every group
if that is the case You can do it in one sort step
( changed the strings for less typing , the POC still stands )
Code:
//S1 EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTIN DD *
H
SOMETHING FOR FILE1
T
H
SOMETHING FOR FILE2
SOMETHING FOR FILE2
T
H
SOMETHING FOR FILE3
SOMETHING FOR FILE3
SOMETHING FOR FILE3
T
H
SOMETHING FOR FILE4
SOMETHING FOR FILE4
SOMETHING FOR FILE4
SOMETHING FOR FILE4
T
//OUT1 DD SYSOUT=*
//OUT2 DD SYSOUT=*
//OUT3 DD SYSOUT=*
//OUT4 DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,1,CH,EQ,C'H'),
PUSH=(51:ID=1))
OUTFIL FNAMES=OUT1,INCLUDE=(51,1,CH,EQ,C'1',AND,
1,1,CH,NE,C'H',AND,
1,1,CH,NE,C'T')
OUTFIL FNAMES=OUT2,INCLUDE=(51,1,CH,EQ,C'2',AND,
1,1,CH,NE,C'H',AND,
1,1,CH,NE,C'T')
OUTFIL FNAMES=OUT3,INCLUDE=(51,1,CH,EQ,C'3',AND,
1,1,CH,NE,C'H',AND,
1,1,CH,NE,C'T')
OUTFIL FNAMES=OUT4,INCLUDE=(51,1,CH,EQ,C'4',AND,
1,1,CH,NE,C'H',AND,
1,1,CH,NE,C'T')