|
View previous topic :: View next topic
|
| Author |
Message |
marc_holmes
New User
Joined: 11 Jun 2014 Posts: 9 Location: England
|
|
|
|
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? |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
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).
So, what selection criteria do you want? |
|
| Back to top |
|
 |
marc_holmes
New User
Joined: 11 Jun 2014 Posts: 9 Location: England
|
|
|
|
| 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. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
OK, with DFSORT there is a PTF available which supports MAGIC=ON on the OPTION statement. However, it is for internal use only.
If it is "easy" in COBOL, perhaps you could reveal an outline of that coding? |
|
| Back to top |
|
 |
marc_holmes
New User
Joined: 11 Jun 2014 Posts: 9 Location: England
|
|
|
|
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. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
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). |
|
| Back to top |
|
 |
marc_holmes
New User
Joined: 11 Jun 2014 Posts: 9 Location: England
|
|
|
|
| OK, thanks, I'll give it a try. |
|
| Back to top |
|
 |
marc_holmes
New User
Joined: 11 Jun 2014 Posts: 9 Location: England
|
|
|
|
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.
OPTION COPY
OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(13,6,CH,EQ,C'HEADER'),
END=(13,6,CH,EQ,C'FOOTER'),PUSH=(761:ID=1))
OUTFIL INCLUDE=(761,1,CH,EQ,C'1',
AND,13,6,CH,NE,C'HEADER',
AND,13,6,CH,NE,C'FOOTER'),
BUILD=(1,760) |
|
| Back to top |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10903 Location: italy
|
|
|
|
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')
|
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
With the four OUTFILs, as enrico has shown in his code, the input data is only read once.
If you have only a small amount of data, this won't be so important. The larger your data, the greater the resource savings. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|