Posted: Wed Jan 06, 2010 3:17 pm Post subject: Retain only the first header
Hi All,
I hope you can help me with a challenge i am facing for creating a DFSORT sort card. I searched but did not find anything which is exactly matching my requirement.
I have multiple files merged into a single file. Each of these input files used for merging will have a header record and a number of detail records. So the final merged file will have multiple header records and detail records. There are no trailers. There is no way to identify a header record uniquely as it has got the run date and time and the program name which created the file (which can vary). My requirement is to select a particular kind of detail record plus only one header record at the top. For any merged output file there will be a header record at the top. I want to use this header.
Code:
Sample input merged file
=================
1201009 0600 ===> Header 1
DTL type 1
DTL type 1
DTL type 1
DTL type 1
DTL type 1
DTL type 1
DTL type 1
DTL type 2
DTL type 2
DTL type 2
DTL type 2
12020090700 ===> Header 2
DTL type 3
DTL type 3
DTL type 3
DTL type 3
DTL type 3
DTL type 4
DTL type 4
DTL type 4
DTL type 4
DTL type 4
Sample DFSORT output file required if i am selecting only detail record type 2
==============================================================================
1201009 0600 ===> Header 1
DTL type 2
DTL type 2
DTL type 2
DTL type 2
The challange i am facing is to only select the first header all the time because the date and time is not known beforehand.
Joined: 02 Dec 2002 Posts: 1618 Topics: 31 Location: San Jose
Posted: Wed Jan 06, 2010 4:08 pm Post subject:
Quote:
There is no way to identify a header record uniquely as it has got the run date and time and the program name which created the file (which can vary).
If this was really true, there would be no way to do what you say you want, because there would be no way to distinguish a header record from a detail record so how could you select one or the other?.
But it appears from your example that the detail records start with 'DTL' and the header records don't. Assuming that's true, you could use a DFSORT job like the following to do what you want. I assumed your input file has RECFM=FB and LRECL=80, but the job can be changed for other attributes.
Code:
//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
1201009 0600 ===> Header 1
DTL type 1
DTL type 1
DTL type 1
DTL type 1
DTL type 1
DTL type 1
DTL type 1
DTL type 2
DTL type 2
DTL type 2
DTL type 2
12020090700 ===> Header 2
DTL type 3
DTL type 3
DTL type 3
DTL type 3
DTL type 3
DTL type 4
DTL type 4
DTL type 4
DTL type 4
DTL type 4
/*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC OVERLAY=(81:SEQNUM,8,ZD)
OUTFIL INCLUDE=(81,8,ZD,EQ,1,OR,
(1,3,CH,EQ,C'DTL',AND,10,1,CH,EQ,C'2')),
BUILD=(1,80)
/*
_________________ Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Worked like magic. I just modified the card to suit my requirement.
Before posting the question here I was also trying out a similar approach to include sequence number and select the one with value 1. But i did not use "outfil include". i just used "include cond" but due to some reason it did not work out (Does both these function differently?). Also, i am new to this trick of adding the sequence number AFTER the actual record length. Learned something new today. Thanks a ton Frank.
Joined: 02 Dec 2002 Posts: 1618 Topics: 31 Location: San Jose
Posted: Thu Jan 07, 2010 12:05 pm Post subject:
Quote:
But i did not use "outfil include". i just used "include cond" but due to some reason it did not work out (Does both these function differently?).
The INCLUDE statement is processed before the INREC statement. The OUTFIL statement is processed after the INREC statement. So anything you do in an INREC statement is NOT seen by an INCLUDE statement, but is seen by an OUTFIL statement. See the following for a Figure that gives more details:
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